- call()
改变方法内this的指向
- apply()
改变方法内this的指向,传递的参数需要封装成一个数组再传递,传递两个参数数组内就是两个元素,传递三个参数,数组内就是三个元素
- bind()
返回一个方法,这个方法内部的this是我们指定的
call()
let f1 = function(arr,a){
console.log(arr)
console.log(a)
console.log("-------------------")
}
f1.call(null,[1,2])
/**
* [ 1, 2 ]
* undefined
* -------------------
*/
apply()
let f1 = function(arr,a){
console.log(arr)
console.log(a)
console.log("-------------------")
}
f1.apply(null,[1,2])
/**
* 1
* 2
* -------------------
*/
bidn()
let f1 = function(arr,a){
console.log(arr)
console.log(a)
console.log("-------------------")
}
let f2 = f1.bind(null,[1,2])
f2()
/**
* [ 1, 2 ]
* undefined
* -------------------
*/