这是我的代码
function add(x) {
return function (y) {
if (typeof y !== 'undefined') {
x = x + y;
return arguments.callee;
} else {
return x;
}
};
}
add(1)(2)(3)(4)();
答案 0 :(得分:1)
作为替换 - 给它一个名字?:
function add(x) {
return function my_func(y) {
// ^ Named function
if (typeof y !== 'undefined') {
x = x + y;
return my_func;
} else {
return x;
}
};
}
add(1)(2)(3)(4)();
另请阅读:
请勿使用
arguments.callee
:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee