理解javascript的call 、 apply 、 bind

174 阅读1分钟
function add(a,b) { 
  console.log(`type this ${typeof this}, name ${this.name}`);
  console.log(a+b);  
} 
function sub(a,b) { 
  this.name = 'sub name';
  console.log(this);
  console.log(a-b); 
} 
add.call(sub,3,1); 
sub.call(name,3,1);