以下内容来至 es2017 言语范例和 javascript 高等程序设计(第三版)
劈头:标识符的定义
在红宝书 3.1.2 章节中,对标识符做了以下定义:
An identifier is the name of a variable, function, property, or function argument.
对属性名是否是标识符我存有疑问?再看看 ES 范例的定义:
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]
属性接见器
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 toMemberExpression [ <identifier-name-string> ]
and similarlyCallExpression . IdentifierName
is identical in its behaviour toCallExpression [ <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
任何点示意法,都能转换成方括号示意法;反之,则行不通。
总结
属性名不是标识符。红宝书的定义比较浅显,然则总结的不算正确。