User is not a constructor when i declare it in the top of the file
const User = require('./User')
module.exports = class DmChannel {
/**
*
* @param {Client} client
* @param {*} data
*/
constructor(client, data) {
/**
* The client that instantiated this
* @name Base#client
* @type {Client}
* @readonly
*/
Object.defineProperty(this, 'client', { value: client })
this.id = data.id
this.last_message_id = data.last_message_id
this.type = data.type
this.name = data.name
this.flags = data.flags
this.createdTimestamp = Utils.getTimestampFrom(this.id)
this.createdAt = new Date(this.createdTimestamp)
this.user = data.user || data.recipients ? data.recipients.length < 1 ? null : new User(client, data.recipients[0]) : null
this.data_is_available = true
}
}
Someone can explain me why “User” is not a constructor is rejected ?
This one will work :
I require the class User just above the line where I need it
module.exports = class DmChannel {
/**
*
* @param {Client} client
* @param {*} data
*/
constructor(client, data) {
/**
* The client that instantiated this
* @name Base#client
* @type {Client}
* @readonly
*/
Object.defineProperty(this, 'client', { value: client })
this.id = data.id
this.last_message_id = data.last_message_id
this.type = data.type
this.name = data.name
this.flags = data.flags
this.createdTimestamp = Utils.getTimestampFrom(this.id)
this.createdAt = new Date(this.createdTimestamp)
const User = require('./User')
this.user = data.user || data.recipients ? data.recipients.length < 1 ? null : new User(client, data.recipients[0]) : null
this.data_is_available = true
}
}
Thanks !