What is the difference? I looked at the ECMAScript specification, but did not understand. The real code examples that would help much.
If you can explain every line here it would be nice
MemberExpression :
PrimaryExpression
FunctionExpression
MemberExpression [ Expression ]
MemberExpression . IdentifierName
CallExpression :
MemberExpression Arguments
CallExpression Arguments
CallExpression [ Expression ]
CallExpression . IdentifierName
For example
console.log - MemberExpression: MemberExpression . IdentifierName
console.log("hi") - CallExpression : MemberExpression Arguments
What is will be equal
CallExpression : CallExpression . IdentifierName
CallExpression [ Expression ]
CallExpression : CallExpression Arguments
Link for ES http://www.ecma-international.org/ecma-262/5.1/#sec-11.2
2 Answers 2
func()is aCallExpressionthing.funcis aMemberExpressionthingis theobjectof theMemberExpressionfuncis thepropertyof theMemberExpression
thing.func()is aMemberExpressionwithin aCallExpressionthing.funcis thecalleeof theCallExpression
Source: astexplorer.net.
2 Comments
Expressions by enumerating what other expressions they can encompass. If you want to learn what they all mean, refer to the AST specification of a JavaScript parser such as babylon.The relevant parts here are
NewExpression: MemberExpression new NewExpression LeftHandSideExpression: NewExpression CallExpression
which distinguishes the three major left hand side expressions:
- constructor calls
- function/method calls
- primary expressions
And all of them with member accesses in the right places. As such, the difference between the productions you listed is just that a CallExpression always contains a call - and may therefore not be part of the expression after a newoperator.
5 Comments
MemberExpression . IdentifierName and CallExpression . IdentifierNameCallExpression . IdentifierName or CallExpression Arguments I don't imagine this, how it will be (MemberExpression . IdentifierName or MemberExpression Arguments I do imagine it).member().callProperty and member()() (vs member.memberProperty and member()).MemberExpression Arguments - Its CallExpression Right?CallExpression : MemberExpression Arguments