函数调用的几种模式

第一种 函数执行模式

 function add(a,b){

    console.log(this);

    return(a+b);

}

  add();   

this===window

// 在函数执行模式中任何this都指向window!!!

第二种 对象方法调用模式

 function add(){

this.show = function(){

console.log(this);

}

}

var add = new Add();

c.show();

this===c;

// 实例对象调用自己的方法,this 指向实例对象!!!

第三种 构造器的调用模式

function cdd(){

this.show = function (){

console.log(this);

 }

}

var add = new Add();

// 构造函数调用模式,this指向实例对象

原文地址:https://www.cnblogs.com/kevinl7/p/6046283.html