call、apply、bind的区别和异同
我们知道bind,call,apply的作用都是用来改变this指向的,那为什么要改变this指向呢?请看下面的例子:
var name="lucy";
let obj={
name:"martin",
say:function () {
console.log(this.name);
}
};
obj.say(); //martin,this指向obj对象
setTimeout(obj.say,0); //lucy,this指向window对象
可以观察到,正常情况下 say 方法中的 this
转载
2020-11-05 21:24:43 ·
268 阅读 ·
1 评论