Function Syntax

David Herman dherman at mozilla.com
Wed May 11 09:32:00 PDT 2011


> There's no perfect answer. Shorter return syntax ("^" with an ASI change, or my "empty label" idea, "function f(){:g()}") is ugly, adds overhead, and can still be left off by mistake (making for the opposite problem from the capability leak one: returning undefined instead of the intended result of an expression evaluation).

For example:

    array.map(function(x) { x * 2 }) // oops!

Also, any explicit return syntax has a "Tennent" problem just like return does. Moreover, it forces programmers to write imperatively (return is a non-local jump), when so much of JS code makes effective use of expression-based programming -- for example, the popular "method chaining" style, which is essentially functional programming with methods.

> I still think the completion value leak problem is manageable with docs, tools, and resort to good old "function" long-hand syntax. Opinions?

I agree. But I am sympathetic to Doug's concern about further overloading the curly-brace syntax.

Dave



More information about the es-discuss mailing list