optional "function" keyword

Thaddee Tyl thaddee.tyl at gmail.com
Tue Mar 6 10:07:34 PST 2012


On Tue, Mar 6, 2012 at 6:50 PM, Isaac Schlueter <i at izs.me> wrote:
> A great many letters have been typed regarding the number of letters in the
> word "function".
>
> What if we just made the keyword "function" entirely optional, dart-style?
>
> ShortNamedFunctionDeclaration :Identifier <no_linebreak> ( FormalParameterListopt )
> <no_linebreak> { FunctionBody }
> ShortNamedFunctionExpression :Identifier <no_linebreak> ( FormalParameterListopt )
> <no_linebreak> { FunctionBody } Note that the identifier is no longer
> optional, and that no linebreak is allowed between the parameter list and
> the body, unlike current function decl/exprs.
> myList.forEach(x (item) {
>   item += 2
>   doSomethingElse(item)
>   assert(typeof x === "function")
> })

An interesting property of this syntax is that anonymous functions can
be written this way:

    myList.forEach(λ (item) { doWith(item) })

(it can also be `lambda (item) { ... }`)


More information about the es-discuss mailing list