Function.prototype.call 内部实现探讨续
在上一篇博文中,最后讨论Function.prototype.call的内部实现近似为:
function call(a,b,c){ if(this === call){ a(b,c); }else{ this(b,c); }}?应修正为:
function call(a,b,c){ if(this === call){ a.call(b,c); }else{ this(b,c); }}?证明过程如下:
function f1(){ alert(this.xxx);}f1.xxx = "f1xxx";function f2(){ alert(2);}f2.xxx = "f2xxx";Function.prototype._call = Function.prototype.call;Function.prototype.call = function(bind,arg){ alert(this); this._call(bind,arg);}var f3 = f1.call;f1.call(f2);f3.call(f1,{xxx:"xxx"})?通过最后alert出来的结果,可以看到Function.prototype.call.call确实调用了两次call方法。 1 楼 gr205925 2011-10-15 这篇更看不明白,这个两次是怎么证明出来的。