为什么我不能使用带有箭头功能的此关键字来访问年龄,而我必须先参考人对象然后再参考年龄?
const person = {
firstName: 'John',
lastName: 'Doe',
age: 20,
hobbies: ['Boxing', 'Riding', 'Running'],
address: {
Street: 14,
city: 'NewYork'
},
getBirthYear: () => 2019 - this.age, // showing NaN
getBirthYear: () => 2019 - person.age // working correctly
}
console.log(person.getBirthYear());
为什么我需要用人来获取年龄值