看别人在讨论,于是整理了下,大家来看看下面代码中1-11分别输出的答案是什么???(不要试过再说)
var obj={ a:1, b:2, add:function(c,d){ console.log(this.a+this.b+c+d); } } var a=b=0; //1 obj.add(3,4); //2 var add=obj.add; add(3,4); //3 obj.add.call(this,3,4); //4 obj.add.call(null,3,4); //5 obj.add.call(window,3,4); //6 obj.add.apply(this,[3,4]); //7 obj.add.apply(null,[3,4]); //8 obj.add.apply(window,[3,4]); //9 var addOne=obj.add.bind(this); addOne(3,4); //10 var addTwo=obj.add.bind(obj); addTwo(3,4); //11 var Object={}; var addThree=obj.add.bind(Object); addThree(3,4);