call,apply,bind的用法和区别:

174 阅读1分钟

共同点:三者都能是改变this的指向;

不同点: 1.call和apply不能产生新的函数,只是暂时改变this的指向;

2.bind将对象属性绑定给this,并且产生了新的对象;

3.call和apply的第一个参数都是this,call的属性参数是单个传递,apply是按数组传递;

eg:

var boo = {
name :'tangxiong'
}

function tt(value){
consloe,log('hello tangxiong' + this.name + value)
}

tt.call(boo,'23')
tt.applay(boo,['23']) //自动的调用

var tx = tt.bind(boo)//产生了一个新对象

```