0

我正在尝试制作以下 nodejs 模块:

exports.method = function () {      
  var init = true;

  return function (args) {
     console.dir(args);
  };
};

但是当我调用此方法时,我没有收到控制台消息:

require('./module.js').method({test: 1});

它返回一个函数而不是调用它。

4

1 回答 1

5

您需要执行外部函数,否则您只需将其分配给exports.method.

换句话说:

exports.method = function () {      
  var init = true;

  return function (args) {
     console.dir(args);
  };
}();

注意尾随()

于 2013-04-11T04:09:04.503 回答