代码演示
-- apply 临时改变函数的this指向,用数组传所有参数;Math.max.apply(null,[1,4,6,2]);-- call 临时改变函数的this指向,一次传所有参数Math.max.call(null,1,4,6,2);-- bind 改变函数的this指向,多次传所有参数;返回永久改变this指向的函数;var arr=[1,10,5,8,12];var max=Math.max.bind(null,arr[0])max=Math.max.bind(null,arr[1],arr[2])max=Math.max.bind(null,arr[4])console.log(max()); //12,分两次传参
参考
彻底弄懂bind,apply,call三者的区别 Function.prototype.bind() Function.prototype.call() Function.prototype.apply()
