首页 > 技术文章 > js中Function方法

yangxiaoguai132 2016-03-11 11:18 原文

function.apply(thisArg,argArray)

apply方法调用function,传递一个会绑定到this上的对象和一个可选的数组作为参数。

apply方法被用在apply调用模式中。

例如:

 1 Function.method("bind",function(that){
 2             var method=this,
 3                 slice=Array.prototype.slice,
 4                 args=Array.prototype.slice.apply(arguments,[1]);
 5             return function(){
 6                 return method.apply(that,args.concat(slice.apply(arguments,[0])));
 7             };
 8           var x=function(){
 9             return this.value;
10           }.bind({value:666});
11           alert(x());
12         });

 

推荐阅读