简体   繁体   English

如何替换arguments.callee; 在JavaScript中

[英]How can I replace arguments.callee; in javascript

This is my code 这是我的代码

function add(x) {
    return function (y) {
        if (typeof y !== 'undefined') {
            x = x + y;
            return arguments.callee;
        } else {
            return x;
        }
    };
}
add(1)(2)(3)(4)();

As replace in - give it a name?: 作为替换-给它起个名字吗?:

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)();

Also please read: 另请阅读:

Please don't use arguments.callee : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee 请不要使用arguments.calleehttps : //developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Functions/arguments/callee

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM