Function Syntax

Brendan Eich brendan at mozilla.com
Wed May 11 11:31:48 PDT 2011


On May 11, 2011, at 11:26 AM, Jorge wrote:

> On 11/05/2011, at 18:53, Brendan Eich wrote:
> 
>> (...)
>> 
>> 3c. The use of {| (possibly with space in between) is an unambiguous extension, but formal parameters inside |...| delimiters creates a problem for http://wiki.ecmascript.org/doku.php?id=harmony:parameter_default_values. We would need the default value expression to be parenthesized if its precedence were | (bitwise-or) or looser.
> 
> I don't think it's a problem, after all that's what parenthesis are for.

No, formal parameter list delimiting is what parentheses in function-like *declarations and expression* are for. In JS.

More below, but confirmation bias or assuming the Ruby conclusion seems a real problem in evaluating this idea _qua_ JS.


>> Other than these, AFAICT blocks as lambdas offering shorter function-like syntax are pretty good.
> 
> Yes, [ ... ].forEach( {| v, i, o | ... } ) would be awesome, and {| n | while (n--) buffer[n]= 0 }( buffer.length ) is even beautiful.

It's not bad but the || are a bit odd for JS. Not for Ruby, for JS.


>> Should we reconsider them?
> 
> Yes. Ruby's blocks, pure win. :-)

You skipped 3b.

Rubyists should view their pre-existing knowledge and experience through a skeptical lens. Pretend you're new to JS and you don't know Ruby (or Smalltalk). You do know languages with statements, including things like break, continue, and return.

/be



More information about the es-discuss mailing list