“x不是构造函数”,即使它被定义为

时间:2017-11-23 23:01:43

标签: javascript class constructor

client.js

const CSGO = require('./csgo')

module.exports = class Client {
    constructor() {

    }

    csgo(data) {
        return new Promise((resolve, reject) => {
            resolve(new CSGO(data))
            .catch(err => reject(err))
        })
    }

};

csgo.js

module.export = class CSGO {
    constructor(content) {
        // super();
        this.content = content;
    }

    parseData() {
        console.log(content + ' it works')
    }
}

test.js

var client = require('./src/client.js')

const game = new client();

game.csgo('hello')

我正在尝试从test.js =>传递内容client.js => csgo.js,但是当我尝试拨打game.csgo(contents')然后从客户端创建一个包含数据的new CSGO时,我得到一个TypeError说CSGO不是构造函数。我该怎么办?

1 个答案:

答案 0 :(得分:0)

我认为这只是一个错字。如果您在csgo.js中提到module.export

,则表示module.exports
相关问题