简体   繁体   English

JavaScript简单代码未运行

[英]JavaScript simple code not running

I'm watching a tutorial and I tried running the following code but it doesn't run. 我正在观看教程,并尝试运行以下代码,但未运行。

var person = {
  'address': {
    'street': 'Rose Road',
    'city': 'somewhere',
    'state': 'CA'
  },
  'isfromState': fucntion(state) {
    return (this.address.state === state);
  }
}
console.log(person.isfromState('blah'));

Instead, it gives me this error Exception: SyntaxError: missing } after property list and I can't find the mistake. 相反,它Exception: SyntaxError: missing } after property list给了我这个错误Exception: SyntaxError: missing } after property list ,但我找不到错误。

'isfromState': fucntion(state) { // <--- fucntion isn't a keyword
  return (this.address.state === state);
}

Should be: 应该:

'isfromState': function(state) { // <--- use function
  return (this.address.state === state);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM