标签:思路 java cal nbsp ret 额外 call pre logs
call 与 apply 的区别是 cal 只能一个一个的传递参数,apply 是可以通过数组来传递参数, bind 需要进行一次额外的声明,
call 实例
var arr = {num: 2};
function aa(val1, val2) {
return this.num+val1+val2;
}
console.log(aa.call(arr, 2,3)); // functionname.call(obj, functionArguments)
apply 实例
var obj = {num: 2}; var obj2 = {num: 3}; function add(val1, val2, val3) { return this.num+val1+val2+val3; } var arr = [1,2,3]; console.log(add.apply(obj, arr)); console.log(add.apply(obj2, arr));
bind 实例
var obj = {num: 5}; function add(val1, val2, val3) { return this.num+val1+val2+val3; } var bound = add.bind(obj); console.log(bound(3,4,5));
标签:思路 java cal nbsp ret 额外 call pre logs
原文地址:http://www.cnblogs.com/bbb324/p/6812392.html