有没有办法通过Function.prototype.bind重新绑定已绑定到另一个对象的函数?
var a={}; var b={}; var c=function(){ alert(this===a); }; c(); // alerts false c=c.bind(a); c(); // alerts true c=c.bind(b); c(); // still alerts true
解决方法
Is there a way to rebind a function that is already bound to another object via Function.prototype.bind?
从ES2015 spec开始,关于Function.prototype.bind:
19.2.3.2 Function.prototype.bind ( thisArg,…args)
[…]
Note 2: If Target is an arrow function or a bound function then the thisArg passed to this method will not be used by subsequent calls to F.
对于早期版本也是如此.