语法似乎是正确的,我不明白,这里是 错误:app.js:73未捕获的ReferenceError:未定义getBirthyear 代码:
const person = {
name: 'Tommy',
age: 32,
location: {
state: 'Missouri',
city: 'louisisana',
street: '1 marcia drive',
job: 'web dev'
},
getBirthyear: function() {
return 2018 - this.age;
}
}
let val;
val = getBirthyear();
document.write(val);
答案 0 :(得分:1)
您可以使用person.getBirthday()
来调用它,因为它是person