Function inside if statement?
P T Withington
ptw at pobox.com
Wed Feb 6 04:43:18 PST 2008
On 2008-02-05, at 18:53 EST, Brendan Eich wrote:
> SpiderMonkey has for about a decade implemented three kinds of
> function forms: definitions, expressions, and statements. This is an
> example of the last -- it's a function definition, syntactically,
> except produced as a child of another statement, possibly even a
> block -- a position which the ES3 grammar cannot produce a function
> definition. Only if control flow reaches the function statement does
> it bind its name.
> This is an extension allowed by ES3 chapter 16.
I would endorse standardizing this behavior.
FWIW, the Openlaszlo compiler/translator extends es3 in a similar
fashion to support conditional compilation. An `if` that tests a
compile-time constant will be optimized away by the compiler.
More information about the Es4-discuss