<分区>
在 [MDN][绑定(bind)]
我们看到这段代码是这样的
this.x = 9; // this refers to global "window" object here in the browser
var module = {
x: 81,
getX: function() { return this.x; }
};
module.getX(); // 81
var retrieveX = module.getX;
retrieveX();
// returns 9 - The function gets invoked at the global scope
var boundGetX = retrieveX.bind(module);
boundGetX();
是的,我知道绑定(bind)会改变“this”的值,但我混淆了下面的一段代码
var demo=boundGetX.bind(this);// or boundGetX.bind(window);
demo();// still 81
再次使用绑定(bind),我认为它会将“this”点更改为“window”,但事实并非如此。 我想知道为什么。