解释bindbind()函数

Nik*_*Nik 6 javascript functional-programming function-binding

有人可以解释这个功能吗?

var bindbind = Function.prototype.bind.bind(Function.prototype.bind);
Run Code Online (Sandbox Code Playgroud)

我理解它产生的结果:

var bindedContextFunc = bindbind(function)(context);
bindedContextFunc(args);
Run Code Online (Sandbox Code Playgroud)

但是不明白创建这个功能的过程,我的意思是部分 bind(Function.prototype.bind)

Ber*_*rgi 4

好的。我们这里有三倍的Function.prototype.bind函数,其(简化的)代码

function bind(context) {
    var fn = this;
    return function() {
        return fn.apply(context, arguments);
    }
}
Run Code Online (Sandbox Code Playgroud)

我将用一种更实用的风格来缩写,其中有很多部分应用:bind fn (context) -> fn context

那么它有什么作用呢?你已经得到了bindbind.call(bind, bind)或者bind (绑定)。让我们将其扩展为绑定bind。如果我们现在为其提供一些参数会怎么样?

绑定绑定(绑定)(fn)(上下文)

绑定绑定(fn)(上下文)

绑定fn(上下文)

fn上下文

我们到了。我们可以将其分配给一些变量以使结果更清晰:

绑定绑定=绑定绑定(绑定)

bindfn = 绑定任何东西(fn)//绑定fn

contextbindfn = bindfn任何内容(上下文)//fn上下文

结果 = contextbindfn任何内容(参数)//fn上下文(参数)