首页 > 解决方案 > BindingIdentifier 和 IdentifierReference 有什么区别

问题描述

让我们看看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

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

标签: ecmascript-6

解决方案


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

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

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


推荐阅读