Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试制作以下 nodejs 模块:
exports.method = function () { var init = true; return function (args) { console.dir(args); }; };
但是当我调用此方法时,我没有收到控制台消息:
require('./module.js').method({test: 1});
它返回一个函数而不是调用它。
您需要执行外部函数,否则您只需将其分配给exports.method.
exports.method
换句话说:
exports.method = function () { var init = true; return function (args) { console.dir(args); }; }();
注意尾随()
()