0
我有一個文件。 a.js級聯需要在NodeJs中,需要一個需要另一個文件的文件NodeJs
class A{
constructor(name){
this.name = name;
}
displayName(){
console.log(this.name);
}
}
module.exports = A;
另一個文件 common.js
const A = require('./a');
exports.A;
另一個文件b.js
const common = require('./common');
var a = new common.A('My name is khan and I am not a terrorist');
a.displayName();
我得到一個錯誤A是不是一個構造ctor。 請幫忙,怎樣才能完成。 請原諒我愚蠢的錯誤,我是新手。
在a.js中你應該做的是:module.exports = A – WilomGfx
並且在common.js中保持一致** module.exports = A ** – lomboboo
對不起,它的module.exports =只有一個。讓我編輯問題。 – Imran