语法错误:属性列表后缺少 }

对象初始值设定项 语法中某处出现错误时,就会发生 JavaScript 异常 "属性列表后缺少 }"。实际上可能是缺少大括号,但也可能是缺少逗号。

¥The JavaScript exception "missing } after property list" occurs when there is a mistake in the object initializer syntax somewhere. Might be in fact a missing curly bracket, but could also be a missing comma.

信息

¥Message

SyntaxError: missing } after property list (Firefox)
SyntaxError: Unexpected identifier 'c'. Expected '}' to end an object literal. (Safari)

错误类型

¥Error type

SyntaxError

什么地方出了错?

¥What went wrong?

对象初始值设定项 语法中某处有错误。实际上可能是缺少大括号,但也可能是缺少逗号。还要检查任何右大括号或圆括号的顺序是否正确。更好地缩进或格式化代码也可能会帮助你看清丛林。

¥There is a mistake in the object initializer syntax somewhere. Might be in fact a missing curly bracket, but could also be a missing comma, for example. Also check if any closing curly braces or parenthesis are in the correct order. Indenting or formatting the code a bit nicer might also help you to see through the jungle.

示例

¥Examples

忘记逗号

¥Forgotten comma

通常,对象初始值设定项代码中缺少逗号:

¥Oftentimes, there is a missing comma in your object initializer code:

js
const obj = {
  a: 1,
  b: { myProp: 2 }
  c: 3
};

正确的是:

¥Correct would be:

js
const obj = {
  a: 1,
  b: { myProp: 2 },
  c: 3,
};

也可以看看