是(函数表达式){使用分组运算符包围函数表达式}实际上有效吗?

时间:2012-06-02 15:33:12

标签: javascript

基于官方ECMA-262 edition 5.1 June 2011 standard

The grammar summary defines that a grouping operator(parentheses) may only contain an expression

PrimaryExpression :

this
Identifier
Literal
ArrayLiteral
ObjectLiteral
( Expression )

表达式只能是Assignmentexpression(或其序列)(滚动到section A.3的末尾)

Expression :

AssignmentExpression
Expression , AssignmentExpression

因此,根据ECMA-262版本5.1,以下内容应该是错误的:(FunctionExpression)

1 个答案:

答案 0 :(得分:2)

经过一番挖掘,我发现它实际上是有效的。以下是完整的推导(将其追溯到section A.3的末尾,并从Expression开始向上推导:

Expression -> AssignmentExpression -> ConditionalExpression ->
LogicalORExpression -> LogicalANDExpression -> 
BitwiseORExpression -> BitwiseXORExpression -> 
BitwiseANDExpression -> EqualityExpression -> 
RelationalExpression -> ShiftExpression -> AdditiveExpression -> 
MultiplicativeExpression -> UnaryExpression -> 
PostfixExpression -> LeftHandSideExpression -> NewExpression -> 
MemberExpression -> FunctionExpression