Expression Closures as Compliment to Arrow Functions

Brendan Eich brendan at
Tue Mar 24 13:35:51 UTC 2015

Jacob Parker wrote:
> Either I'm wrong, or that's missing some parens.

No, test it yourself in Firefox (s/print/console.log/) or SpiderMonkey.

> 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?

No. :-P

But seriously, I'm not sure what your last line means. The mis-parsing 
due to precedence inversion means SpiderMonkey (in Firefox) returns f, 
not "f", as the value that initializes y, given the minimally 
parenthesized testcase:

function f() {return "f"}
var x = 3;
var y = function (a) a ? f : x++(1);

> FWIW, the consise body of arrow functions won't allow the original 
> format, and must have surrounding parens.

Yes, arrows are low-precedence (AssignmentExpression alternatives), so 
they don't suffer from precedence inversion.

> Would just allowing consise bodies on functions work?

No, because function expressions are high-precedence (PrimaryExpression).


More information about the es-discuss mailing list