Node.js模块导出多个类

我有2个文件称为a.js和b.js,都包含类。 我试图导入并使用下面的代码在类A中创build类B的新实例

a.js

module.exports.A = A; var classB = require('./b.js').B; A.protoype.Init = function(){ this.B = new classB(); 

b.js

 module.exports.B = B; function B(a_class) { this.a = a_class; } 

我收到以下错误

TypeError:undefined不是这个函数.B = new class B();

您尚未在您的a.js文件中定义您的A类:

a.js – 我为你的A类添加了一个构造函数:

 module.exports.A = A; var classB = require('./b.js').B; function A() {} A.protoype.Init = function(){ this.B = new classB(); }