Difference between CallExpression and MemberExpression

后端 未结 2 1706
半阙折子戏
半阙折子戏 2021-01-05 12:59

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

相关标签:
2条回答
  • 2021-01-05 13:29
    • 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.

    0 讨论(0)
  • 2021-01-05 13:30

    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.

    0 讨论(0)
提交回复
热议问题