问题
I'm trying to prove that a simple function call such as
window.alert();
is valid EcmaScript 2016 (7th Edition) grammar. Working backward, with the expectation this is an ExpressionStatement, I see that it fits the pattern MemberExpression Arguments which is a CallExpression. And, section 12.3 defines LeftHandSideExpression as possibly a CallExpression. Now, my problem is that section 12.15 AssignmentExpression seems to require that LeftHandSideExpression be followed by either an AssignmentExpression or an AssignmentOperator and AssignmentExpression cannot be ;
I'm probably missing something simple. Direction will be greatly appreciated.
回答1:
An AssignmentExpression does not necessarily need to be an assignment, it only means "an assignment could stand here". It can also consist of solely a ConditionalExpression. And now we need to go down the whole chain of associativity rules:
A ConditionalExpression can contain a ternary operator or consist solely of a LogicalORExpression. A LogicalORExpression can contain an ||
operator or consist solely of a LogicalANDExpression. And so on: A LogicalANDExpression can consist solely of a BitwiseORExpression which can consist of solely a BitwiseXORExpression which can consist of solely a BitwiseANDExpression which can consist of solely an EqualityExpression which can consist of solely a RelationalExpression which can consist of solely a ShiftExpression which can consist of solely an AdditiveExpression which can consist of solely a MultiplicativeExpression which can consist of solely an ExponentiationExpression which can consist of solely a UnaryExpression which can consist of solely an UpdateExpression.
Which finally can consist of the LeftHandSideExpression that we were looking after.
来源:https://stackoverflow.com/questions/42791008/is-a-javascript-function-call-a-lefthandsideexpression-thus-an-expressionstatem