Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在不影响接收器的情况下使用bind进行部分应用_Javascript_Partial Application_Function Binding - Fatal编程技术网

Javascript 在不影响接收器的情况下使用bind进行部分应用

Javascript 在不影响接收器的情况下使用bind进行部分应用,javascript,partial-application,function-binding,Javascript,Partial Application,Function Binding,如果我想部分应用一个函数,我可以使用bind,但似乎我必须影响函数的接收者(bind的第一个参数)。这是正确的吗 我想使用bind执行部分应用程序,而不影响接收器 myFunction.bind(iDontWantThis, arg1); // I dont want to affect the receiver 在不影响接收器的情况下,使用bind部分应用程序 那是不可能的bind被明确设计为部分应用“第零个参数”this值,以及可选的更多参数。如果您只想修复函数的第一个(可能更多)参数,但

如果我想部分应用一个函数,我可以使用
bind
,但似乎我必须影响函数的接收者(bind的第一个参数)。这是正确的吗

我想使用
bind
执行部分应用程序,而不影响接收器

myFunction.bind(iDontWantThis, arg1); // I dont want to affect the receiver
在不影响接收器的情况下,使用
bind
部分应用程序

那是不可能的
bind
被明确设计为部分应用“第零个参数”
this
值,以及可选的更多参数。如果您只想修复函数的第一个(可能更多)参数,但不绑定此,则需要使用不同的函数:

Function.prototype.partial = function() {
    if (arguments.length == 0)
        return this;
    var fn = this,
        args = Array.prototype.slice.call(arguments);
    return function() {
        return fn.apply(this, args.concat(Array.prototype.slice.call(arguments)));
    };
};

当然,这样的函数在许多库中也可用,例如,等等。但是,没有本地等效函数。

您不能。使用不同的
partial
功能,而不是
bind
。相关,如果不重复: