简体   繁体   中英

“x is not a constructor” even though it's defined

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')

I'm trying to pass contents from test.js => client.js => csgo.js, but when I try to call game.csgo(contents') then from the client create a new CSGO with the data, I am getting a TypeError saying that CSGO is not a constructor. What should I do?

I believe it's just a typo. You have module.export when you mean module.exports in csgo.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM