[英]How can ECMAScript AssignmentExpression production rule produce `foo = 42`?
As the spec states (yes, 5.1, that's intentional):正如规范所述(是的,5.1,这是故意的):
AssignmentExpression :
ConditionalExpression
LeftHandSideExpression = AssignmentExpression
LeftHandSideExpression AssignmentOperator AssignmentExpression
Based on this definition, I don't understand how a simple foo = 42
assignment is valid.基于这个定义,我不明白一个简单的foo = 42
赋值是如何有效的。
My understanding is, that foo =
should always be followed by either a ConditionalExpression
or essentially another assignment, but in that case, how will the production terminate if I don't use a ConditionalExpression
?我的理解是, foo =
后面应该总是跟一个ConditionalExpression
或者本质上是另一个赋值,但是在这种情况下,如果我不使用ConditionalExpression
,生产将如何终止? All further AssignmentExpression
rules require either a ConditionalExpression
or another AssignmentExpression
.所有进一步的AssignmentExpression
规则都需要一个ConditionalExpression
或另一个AssignmentExpression
。
What am I missing here?我在这里想念什么?
The expression after the =
operator must always be an AssignmentExpression . =
运算符之后的表达式必须始终是一个AssignmentExpression 。 This AssignmentExpression will often consist not of another assignment, but a plain ConditionalExpression , which in turn will consist of a simpler expression that might contain an operator or not, all the way down through the operator precedence hierarchy to the Literal that your number 123
forms.这个AssignmentExpression通常不包含另一个赋值,而是一个普通的ConditionalExpression ,它又包含一个可能包含或不包含运算符的更简单的表达式,一直到运算符优先级层次结构,一直到您的数字123
forms 的字面量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.