简体   繁体   中英

What does `ExpressionNoIn` mean in the ECMAScript spec?

I'm doing a bit of a deep dive into the for loop and encountered ExpressionNoIn in the spec at http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.3

What does it mean?

It is explained in section 11.14 "Comma Operator ( , )":

逗号操作员ECMA Spec

The *NoIn has the same structure, except that in excludes the use of the in keyword, section 11.8 "Relational Operators":

关系运算符ECMA Spec

The spec says:

The "NoIn" variants are needed to avoid confusing the in operator in a relational expression with the in operator in a for statement.

As in may be used in two ways:

for (var x in foo) { ... }

Or:

if ('x' in foo) { ... }

The "NoIn" variants are there to make it impossible to use the second version of in above in the first expression of the for loop. So, the following code is invalid:

for (y = 'x' in foo; y; y = false) { ... }

ExpressionNoIn is a non terminal from which all expressions can be derived, expect the in operation (ie 'prop' in obj ).

Follow A3 from the bottom (where ExpressionNoIn is defined) to the first *NoIn non-terminal which does not contain a (different) *NoIn non-terminal anymore:

RelationalExpression :
    ShiftExpression
    RelationalExpression < ShiftExpression
    RelationalExpression > ShiftExpression
    RelationalExpression <= ShiftExpression
    RelationalExpression >= ShiftExpression
    RelationalExpression instanceof ShiftExpression
    RelationalExpression in ShiftExpression

RelationalExpressionNoIn :
    ShiftExpression
    RelationalExpressionNoIn < ShiftExpression
    RelationalExpressionNoIn > ShiftExpression
    RelationalExpressionNoIn <= ShiftExpression
    RelationalExpressionNoIn >= ShiftExpression
    RelationalExpressionNoIn instanceof ShiftExpression

I guess that makes it easier to distinguish for loops from for/in loops.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM