BindingIdentifier 和 IdentifierReference 有什么区别

Max*_*Pro 1 ecmascript-6

让我们看看http://www.ecma-international.org/ecma-262/#sec-expressions

如你看到的:

IdentifierReference[Yield, Await]:
    Identifier
    [~Yield]yield
    [~Await]await

BindingIdentifier[Yield, Await]:
    Identifier
    [~Yield]yield
    [~Await]await

Identifier:
    IdentifierName but not ReservedWord
Run Code Online (Sandbox Code Playgroud)

两者都Identifiers (Binding and Reference)包含相同的东西。这有什么意义呢?它们有什么不同?

Ber*_*rgi 5

关键是它们出现在不同的上下文中并且具有与之相关的不同算法。

  • AnIdentifierReference是在表达式中使用的变量名称,使用ResolveBinding评估引用
  • ABindingIdentifier是一个变量名,用于创建绑定 - 在变量和函数声明中、在参数中、在解构中、在catch子句中、在for子句中等。

在他们的EarlyErrors中, anIdentifierReference可能引用evalor argument,但是BindingIdentifier为它们创建绑定是一个语法错误(在严格模式下)。他们共享的唯一算法是StringValue。AnIdentifierReference具有IsValidSimpleAssignmentTarget检查和评估,而 aBindingIdentifier具有BoundNamesBindingInitialization过程。