【发布时间】:2021-02-15 18:53:55
【问题描述】:
如何在对象内部的Arrow function 中获取值。
我想访问该对象的其他属性。
let obj = {
name:'Ashu',
age:123,
show: ()=>{
// I want to print Name and Age how to do that
// Is there any other way to do get Name and Age Property
// I don't want to replace the Arrow function
console.log(obj.name, obj.age);
}
}
obj.show()
【问题讨论】:
-
您不能使用
this。你也不能.bind()箭头函数 -
“有没有其他方法可以获取姓名和年龄属性。我不想替换箭头函数”如果你不想替换箭头功能那么就没有别的办法了。
-
@FelixKling,太酷了。谢谢。
标签: javascript json ecmascript-6 arrow-functions