arrow function syntax simplified

Claus Reinke claus.reinke at talk21.com
Wed Mar 28 07:42:49 PDT 2012


> The ambiguity between a block body and an object literal expression body,
> which we would prefer to resolve in favor of object literal. The solutions
> considered before this edit were:
>
> * http://wiki.ecmascript.org/doku.php?id=strawman:block_vs_object_literal
>
> * Two-token lookahead restriction per 
> http://wiki.ecmascript.org/doku.php?id=strawman:arrow_function_syntax&rev=1307297899#grammar_changes
>
> Both are hairy and not near consensus in TC39. The first isn't backward-
> compatible on edge cases that probably exist on the web. The second is
> future-hostile.

An alternative suggestion was to default to object, but to use an empty
statement prefix to get an unambiguous block {; ..}. Then, we'd have

- statement context: default to block, use parens ({..}) to get object
- expression context: default to object, use empty statement {;..} to get 
block

{; ..} might be a notation-alternative to do-expressions, saving a valuable
keyword. This would require compatible completion-value semantics.

Claus
 



More information about the es-discuss mailing list