最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

“用户”不是类中的构造函数

网站源码admin41浏览0评论

“用户”不是类中的构造函数

“用户”不是类中的构造函数

当我在文件顶部声明它时,用户不是构造函数

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
    }
}

有人可以解释为什么“用户”不是构造函数被拒绝了吗? 这一个会起作用: 我需要在我需要的行上方的 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)
        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
    }
}

谢谢!

回答如下:
发布评论

评论列表(0)

  1. 暂无评论