1、相同点:都是函数调用的操作,并修改函数的调用者
2、不同点:
1) call调用时传递的参数是使用普通逗号隔开传参方式
2) apply调用时的参数是使用数组[...args]
3) bind调用时参数和call一样,但bind的返回值是一个函数,必须手动调用
let o2 = { x: 1, y: 2, z: 3 }
function fn(a, b) {
return this.x + this.y + this.z + a + b
}
// fn.call(target,...args)
rt = fn.call(o2, 4, 5) // 15
console.log('call=', rt)
// fn.apply(target,[...args])
rt = fn.apply(o2, [4, 5]) // 15
console.log('aplly=', rt)
// fn.bind(target,...args) ---> function
let f = fn.bind(o2, 4, 5)
rt = f()
console.log('bind=', rt)