Is the 'catch' method name of JS Promises/A+ invalid since it's a JS keyword?

北城余情 提交于 2019-11-28 13:30:45
Bergi

What am I missing?

A property name is not an identifier, it can use any identifier name. From the spec on Property Accessors:

MemberExpression : MemberExpression . IdentifierName
CallExpression : CallExpression . IdentifierName

and identifiers:

Identifier :: IdentifierName but not ReservedWord

You can use any arbitrary identifer name (but not things like integers) in a dot property access, but you can't use those that are [reserved] keywords as identifier, e.g. in a variable or function name.

However, this did change with ES5, back in EcmaScript 3 property names were required to be identiers. That's why you still need to use the bracket notation for keywords if you want to support legacy browsers; and it's the reason why your linter complains about it. Same holds for property names in object literals.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!