我正在观看教程,但我尝试运行以下代码,但它没有运行。
var person = {
'address': {
'street': 'Rose Road',
'city': 'somewhere',
'state': 'CA'
},
'isfromState': fucntion(state) {
return (this.address.state === state);
}
}
console.log(person.isfromState('blah'));
相反,它给了我这个错误Exception: SyntaxError: missing } after property list
,我找不到错误。
答案 0 :(得分:3)
'isfromState': fucntion(state) { // <--- fucntion isn't a keyword
return (this.address.state === state);
}
应该是:
'isfromState': function(state) { // <--- use function
return (this.address.state === state);
}