function eat(x, y) { 
      console.log(x + y);
      console.log(this); 
}function drink(x, y) { 
      console.log(x - y);
      console.log(this); 
} eat.call(drink, 3, 2);输出结果为什么是
drink 中的语句一条也不会执行吗?那为什么 this指向了drink?还做了一些测试如下:    function eat() {
      this.x = 1;
      this.y = 2;
  // this.z = this.x + this.y;
      console.log(this.z);
    }    function drink() {
      this.x = 2;
      this.y = 3;
      this.z = this.x + this.y;      console.log(this);
    }    eat.call(drink);
    var d = new drink();
    eat.call(d)
测试一:测试二:
两次测试中代码区别只有eat中this.z有没有被赋值测试结果怎么理解?

解决方案 »

  1.   

    说实话,进来之前我感觉我对call,apply,bind理解的还可以,但是一看你的帖子,我懵逼了,然后开始搜索了,我觉得你这篇帖子下边紧跟着的推荐的几篇文章讲的都挺好的,可以看看前两篇。
      

  2.   

    call()的第一个参数应该是一个对象,虽然函数也是对象,但一般不会传函数,除非你明确的要把函数当一个对象使用。
     
    函数.call(对象)的作用只是:执行函数,并且把call()第一个参数的对象赋值给函数内的this。仅此而已。