Remix.run Logo
▲ Rohansi 4 hours ago

The function reference is actually evaluated first so your preferred order is actually backwards! Consider this:

  foo.bar(x)
The `foo.bar` field has to be retrieved before the function can be called. It does not evaluate `x` first. That is observable with JS proxies, or you can test with code like this:

  foo()(bar())
▲LtWorf 3 hours ago | parent [-]

Executing the "." operator isn't the same as executing the function.

▲Rohansi 3 hours ago | parent [-]

JS and many other languages have getters so that's not always true.

But my point is that the reference to the function you are calling is actually its own term that needs to be considered in the order of evaluation.

You can also use the IIFE (immediately invoked function expression) pattern that is/was common in JS as an example:

  (function() {
    // ...
  })();
You can use any valid expression in place of a function name, including anything that causes observable side effects.
▲LtWorf 2 hours ago | parent [-]

A "getter" executed on the "." operator isn't the same as executing the function it returns anyway.