Expression Closures as Compliment to Arrow Functions

Bergi a.d.bergi at web.de
Tue Mar 24 13:13:11 UTC 2015


Jacob Parker schrieb:
> Either I'm wrong, or that's missing some parens. Assume the following (the
> only interpretation I can see to not throw a syntax error),
>
>      var y = (function (a) a ? f : x++)(1);
>
> In which case, that could only return `f`, which when printed should print
> the source of f, no?

Uh, I had some problems with that either, but finally got it now. If we 
make the parens explicit, the point is that the expression should be 
evaluated as

   var y = ((function (a) a) ? f : x++)(1); // === f(1)

instead of

   var y = (function (a) (a ? f : x++))(1); // === f

Admittedly, I think arrow functions have same problem. How is

   var y = (a) => a ? f : x++ (1);

evaluated (or is it syntactically valid at all)?

  Bergi



More information about the es-discuss mailing list