绑定函数为null [英] Binding function to null
本文介绍了绑定函数为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function f() {
return this.x
}
f = f.bind(null)
f() // undefined
x = 1
f() // 1
我找不到任何页面它表示绑定到 null
或 undefined
无效。在任何地方写入这个
成为 bind
的第一个参数的链接,未提及异常。有人可以提供某个描述此类行为的链接吗?
I cannot find any page where it says that binding to null
or undefined
has no effect. Everywhere it is written that this
becomes a link to the first argument of bind
, exceptions are not mentioned. Can somebody provide a link to somewhere describing such behaviour?
推荐答案
链接到段落,其中指定了此效果。问题是,falsey 这个
被全局对象替换而不是绑定,但是在绑定函数调用时。
Link to the paragraph, where this effect is specified. The problem was, falsey this
is replaced with global object not while binding, but at the moment of bound function call.
这篇关于绑定函数为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文