Sergey Orlov
Sergey Orlov

Reputation: 331

Operators execution order

I try to evaluate expression in terms of operators precedence and got quite confusing result.

Here is expression: a.b(c).d(e,f).

It is consist of member access and function call operators. According to MDN OperatorPrecedence table member access operator have left-to-right associativity and higher precedence than function call operator.

So in above expression second member access must happened before first function call.

So what I am missing?

Upvotes: 0

Views: 142

Answers (1)

Felix Kling
Felix Kling

Reputation: 816970

member access operator have left-to-right associativity and higher precedence than function call operator.

That just means that a.b(c) is evaluated as (a.b)(c), not a.(b(c)) (which isn't valid anyway).

So in above expression second member access must happened before first function cal

How could that be? foo().bar means to access the property bar of the return value of the function call. Which property should be accessed if the that had to happen before the call?

Or in your example, on which object should .d be accessed? a? a.b?

Upvotes: 2

Related Questions