给定两个模块a
和b
. 我知道可以a
使用module.exports
. 我可能没有正确使用它。
一个.js
function A() { ... }
A.prototype.func = function() { ... }
function test() {
new A().func();
}
test();
module.exports = {
A : new A()
};
test()
工作正常。但以下中断:
b.js
var A = require("./a");
A.func(); //throws an exception
如何导出整个A
模块及其功能?
更新:执行console.log(A)
结束b
(作为第二行),不显示任何A
方法和变量。