Javascript oop未定义值:用于添加作用域的方法

Javascript oop undefined value: Method to add a scope?

本文关键字:添加 作用域 方法 用于 oop 未定义 Javascript      更新时间:2023-09-26

代码:

var test = {
    con: true
};
var conrun= function(){
    return this.con;
};
Function.prototype.curry = function(scope){
    var fn = this;
    var scope = scope||window;
    return function(){
        fn.apply(scope,arguments);
    }
}
conrun = conrun.curry(test);
alert(conrun());
//result:undefined

"curry"方法,函数将返回,"conrun"fonkiyonna"test"添加到。。。

我该怎么办?

您的curry将丢失返回值。将该行更改为:

return fn.apply(scope, arguments);