ES2018 进修笔记(3)标识符

以下内容来至 es2017 言语范例和 javascript 高等程序设计(第三版)

劈头:标识符的定义

在红宝书 3.1.2 章节中,对标识符做了以下定义:

An identifier is the name of a variable, function, property, or function argument.

对属性名是否是标识符我存有疑问?再看看 ES 范例的定义:

Identifier:

IdentifierName but not ReservedWord

属性相干定义

属性

property

part of an object that associates a key (either a String value or a Symbol value) and a value

属性名(上面提到的 key)实际上是 String 或 Symbol 范例值。

属性名

PropertyName [Yield, Await]:

LiteralPropertyName

ComputedPropertyName[?Yield, ?Await]

属性接见器

Property Accessors:

Properties are accessed by name, using either the dot notation:

MemberExpression . IdentifierName
CallExpression . IdentifierName
or the bracket notation:

MemberExpression [ Expression ]
CallExpression [ Expression ]
The dot notation is explained by the following syntactic conversion:

MemberExpression . IdentifierName
is identical in its behaviour to

MemberExpression [ <identifier-name-string> ]
and similarly

CallExpression . IdentifierName
is identical in its behaviour to

CallExpression [ <identifier-name-string> ]
where <identifier-name-string> is the result of evaluating StringValue of IdentifierName.

属性两种示意法:

  • 点示意法,比方:Object.create
  • 方括号示意法,比方:Object['any string']Object['Expression' + 'Expression']

个中,点示意法中请求 . 以后必需随着 IdentifierName。回看上面提到的标识符的定义:

IdentifierName but not ReservedWord

任何点示意法,都能转换成方括号示意法;反之,则行不通。

总结

属性名不是标识符。红宝书的定义比较浅显,然则总结的不算正确。

    原文作者:siwuxie
    原文地址: https://segmentfault.com/a/1190000016235671
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞