相同点:
- 都是用来改变函数的this对象的指向的
- 第一个参数都是this要指向的对象
- 都可以利用后续参数传参
举个例子来说明用处:
var xw = {
name:"xiaowang",
say:function(sex){
console.log("i am "+this.name+",i am a "+sex);
}
}
var xh = {
name:"xiaohong"
}
xw.say.apply(xh,["girl"]);//i am xiaohong,i am a girl
xw.say.call(xh,"girl");//i am xiaohong,i am a girl
xw.say.bind(xh);//function(sex){console.log("i am "+this.name);}
xw.say.bind(xh)("girl");//i am xiaohong,i am a girl