Block lambda is cool, its syntax isn't

Brendan Eich brendan at
Thu Jan 19 11:27:07 PST 2012

Axel Rauschmayer <mailto:axel at>
January 19, 2012 9:31 AM

Rationale: wouldn’t freezing by default be OK for 98% of the cases? If 
you want anything else, you can use a traditional function. Then the 
above syntax as the only function shorthand would be OK.

First, #(params) { body } was proposed by Arv and Alex:

Arv and Alex feel strongly that the shorter function syntax (anything 
shortening 'function' syntax) must not freeze by default.

There was lack of clarity about whether completion value as implicit 
return value was part of the proposal. If so, controvery, since there is 
a completion value leak hazard. TC39 seems to agree the solution there 
is something with different look & feel, such as block-lambdas.

But, making a one-char grawlix shorthand for 'function' while still 
requiring 'return' is not considered enough of a shorthand. A possible 
cure here is to support an alternative body syntax: #(params) expr. 
However, this inverts precedence if done naively. It also runs into 
trouble trying to prefer an object literal over a block statement. I've 
worked on both of these in the context of

This superseded shorter_function_syntax, but ran into grammatical issues 
that have vexed it.

But notice that throughout this, no one advancing a proposal advocated 
freezing by default. JS developers use function objects as mutable 
objects. Not just to set .prototype, also to decorate with ad-hoc and 
meta-data properties. Freezing is not wanted by default.

I agree that for block-lambdas it's easier to say "freeze by default". 
For merely "shorter function syntax", no. Functions are mutable objects 
by default in JS. This matters for minifiers, which may not be able to 
see all the mutations but would love to use shorter syntax for 
'function' syntax, blindly.


More information about the es-discuss mailing list