using reserved words as property names

In ECMAScript, starting from ES5, reserved words may be used as object property names "in the buff". This means that they don't need to be "clothed" in quotes when defining object literals, and they can be dereferenced (for accessing, assigning, and deleting) on objects without having to use square bracket indexing notation.

That said, reserved words may still NOT be used as identifier names. This is stated quite unambiguously in the spec and is stated somewhat emphatically here (if you don't want your eyes to bleed by having to read the actual language spec)...

在ECMAScript中,从ES5开始,保留字可以直接用作对象属性名称。 这意味着,当定义对象字面量时,它们不需要使用引号,并且可以在对象上直接引用(访问,分配和删除),而不必使用方括号索引符号。

也就是说,保留字可能仍然不能用作标识符名称。 这是在规范中非常明确地说明,并在这里有些强调...

The following are keywords and may not be used as variables, functions, methods, or object identifiers, because ECMAScript specifies special behavior for them:

以下是关键字,不能用作变量,函数,方法或对象标识符,因为ECMAScript为它们指定了特殊的行为:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容