function MemoryFix(){
var garbageBox=document.createElement("div");
garbageBox.style.display="none";
garbageBox.style.background="blue";
document.body.appendChild(garbageBox);
var createElement=document.createElement;
document.createElement=function(){
var obj=Function.prototype.apply.apply(createElement,[document,arguments]);//what the fuck?
garbageBox.appendChild(obj);
return obj;
}

以上代码是一个防止memory leak的一个function,不明白的地方是注释的那一处,普通的obj.apply(anotherobj,[参数数组])我明白,通过以上代码知道apply方法梆定在Function.prototype下,但是var obj=Function.prototype.apply.apply(createElement,[document,arguments]);竟然Function.prototype.apply函数对象本身还包含一个apply方法,然后调用,不明白.....

解决方案 »

  1.   

    alert(Function.prototype.apply.__proto__ === Function.prototype)//true
    alert(Function.prototype.apply.prototype.__proto__ === Object.prototype)//true看来Function.prototype.apply.apply中两个apply是同一方法,但是为什么
    var obj=Function.prototype.apply.apply(createElement,[document,arguments]);就成功返回创建的节点
    而var obj=Function.prototype.apply(createElement,[document,arguments]);就不行.....
    头大..
      

  2.   

    简化问题,请高手解释下以下代码的运行机制.var ax = function(k,v){
    return "a|"+k+"|"+v+"|"+this.abc;//a|b|c|abc
    }
    var ttt = {abc : 'abc'}
    alert(Function.prototype.apply.apply(ax,[ttt,["b","c"]]));
      

  3.   

    再簡化得
    alert(ax.apply(ttt,["b","c"]));