解释 bindbind() 函数 [英] Explain bindbind() function
问题描述
有人能解释一下这个功能吗?
Can someone explain this function?
var bindbind = Function.prototype.bind.bind(Function.prototype.bind);
我理解它产生的结果:
var bindedContextFunc = bindbind(function)(context);
bindedContextFunc(args);
但是不明白创建这个函数的过程,我的意思是部分bind(Function.prototype.bind)
But do not understand process of creating this functions, I mean part bind(Function.prototype.bind)
推荐答案
好的.我们这里有三倍的 Function.prototype.bind
函数,其(简化)代码
OK. We have three times the Function.prototype.bind
function here, whose (simplified) code
function bind(context) {
var fn = this;
return function() {
return fn.apply(context, arguments);
}
}
我会用更多的函数式风格来缩写,有很多部分应用:bindfn(context) -> fncontext.
I will abbreviate in a more functional style with lots of partial application: bindfn(context) -> fncontext.
那么它有什么作用呢?你有 bind.call(bind, bind)
或 bindbind(bind).让我们将其扩展为 bindbind.如果我们现在为其提供一些参数会怎样?
So what does it do? You have got bind.call(bind, bind)
or bindbind(bind). Let's expand this to bindbind. What if we now supplied some arguments to it?
bindbind(bind) (fn)(上下文)
bindbind(bind) (fn) (context)
bindbind(fn)(上下文)
bindfn(上下文)
fncontext
我们来了.我们可以把它赋给一些变量,让结果更清晰:
Here we are. We can assign this to some variables to make the result clearer:
bindbind = bindbind(bind)
bindbind = bindbind(bind)
bindfn = bindbindanything(fn) //
bindfn
bindfn = bindbindanything(fn) //
bindfn
contextbindfn = bindfnanything(context) //
fncontext
contextbindfn = bindfnanything(context) //
fncontext
result = contextbindfnanything(args) //
fncontext(args)
result = contextbindfnanything(args) //
fncontext(args)
这篇关于解释 bindbind() 函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!