我收到以下错误:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: undefined is not a function
at /home/ubuntu/nodejs/test.js:4:10
at factorial (/home/ubuntu/nodejs/test.js:17:20)
at Object.<anonymous> (/home/ubuntu/nodejs/test.js:26:1)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:32)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:41)
当我运行此代码时:
var variadic = require('allong.es').variadic;
var trampoline = function (fn) {
return variadic( function (args) {
var result = fn.apply(this, args);
while (result instanceof Function) {
result = result();
}
return result;
});
};
function factorial (n) {
var _factorial = trampoline( function myself (acc, n) {
return n
? function () { return myself(acc * n, n - 1); }
: acc
});
return _factorial(1, n);
}
factorial(10);
//=> 362800
factorial(32768);
//=> Infinity
我是nodejs的新手。我使用apt-get安装了nodejs和npm,并使用npm install allong.es
安装了allong.es。
我该怎么做才能让它发挥作用?
答案 0 :(得分:1)
variadic
功能不是“直接”导出,而是allong.es
的一部分:
var variadic = require('allong.es').allong.es.variadic;
虽然这似乎也有效:
var variadic = require('allong.es').es.variadic;