12

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

asked Dec 26, 2017 at 0:20

2 Answers 2

20
  • func() is a CallExpression
  • thing.func is a MemberExpression
    • thing is the object of the MemberExpression
    • func is the property of the MemberExpression
  • thing.func() is a MemberExpression within a CallExpression
    • thing.func is the callee of the CallExpression

Source: astexplorer.net.

answered Dec 26, 2017 at 0:24
Sign up to request clarification or add additional context in comments.

2 Comments

Can you give me explanations with this ecma-international.org/ecma-262/5.1/#sec-11.2 (about every line MemberExpression and CallExpression) Especially MemberExpression [ Expression ] and CallExpression [ Expression ] or MemberExpression . Expression and CallExpression . Expression
They're defining the grammar of various 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.
4

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.

answered Dec 26, 2017 at 17:57

5 Comments

Explain to me the difference between MemberExpression . IdentifierName and CallExpression . IdentifierName
I readed it! But can you give me example for CallExpression . IdentifierName or CallExpression Arguments I don't imagine this, how it will be (MemberExpression . IdentifierName or MemberExpression Arguments I do imagine it).
@MaximPro member().callProperty and member()() (vs member.memberProperty and member()).
Interesting. MemberExpression Arguments - Its CallExpression Right?
Yes, that's what your question says: CallExpression : MemberExpression Arguments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.