javascript call和apply方法

1.call方法 
调用一个对象的一个方法,以另一个对象替换当前对象。 
call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 
参数 
thisObj 可选项。将被用作当前对象的对象。 
arg1, arg2, , argN 可选项。将被传递方法参数序列。 
2.apply方法 
应用某一对象的一个方法,用另一个对象替换当前对象。 
apply([thisObj[,argArray]]) 
参数 
thisObj 可选项。将被用作当前对象的对象。 
argArray 可选项。将被传递给该函数的参数数组。 

eg:

function hello(a, b){

  console.log("hello, "this.name);

  console.log(a+b);

}

hello.call({name:'world'},10,15);

hello.apply({name:'apply'},[10,15]);

以上两个方法功能相同

原文地址:https://www.cnblogs.com/lyzblog/p/3343035.html