Is a JavaScript function call a LeftHandSideExpression, thus an ExpressionStatement?

99封情书 提交于 2019-12-02 02:06:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!