【发布时间】:2022-11-14 13:02:24
【问题描述】:
我的绑定方式不起作用。请纠正我。
const ob = {
name:'arif',
getName:() => {
console.log(this)
return this.name;
}
}
const x = ob.getName.bind(ob);
console.log(x()); //return the global name!!
【问题讨论】:
-
箭头函数没有这个,普通函数有
-
哦..同意。那么它是如何处理的呢?你能给世界一些KT吗?
-
你不需要在这里创建函数的引用,你可以像
ob.getName()这样简单地调用它,或者如果你想创建变量,那么你需要将函数更改为箭头函数
标签: javascript