Explain the value of "this"
In the code below we intend to call
obj.go() method 4 times in a row.
(2) works differently from
Here’s the explanations.
That’s a regular object method call.
The same, parentheses do not change the order of operations here, the dot is first anyway.
Here we have a more complex call
(expression)(). The call works as if it were split into two lines:
f = obj.go; // calculate the expression f(); // call what we have
f()is executed as a function, without
The similar thing as
(3), to the left of the parentheses
()we have an expression.
To explain the behavior of
(4) we need to recall that property accessors (dot or square brackets) return a value of the Reference Type.
Any operation on it except a method call (like assignment
||) turns it into an ordinary value, which does not carry the information allowing to set