No subject

Tue Oct 5 19:45:06 PDT 2010

NOTE	Several widely used implementations of ECMAScript are known to support=
 the use of FunctionDeclaration as a Statement. However there are significa=
nt and irreconcilable variations among the implementations in the semantics=
 applied to such FunctionDeclarations. Because of these irreconcilable diff=
erences , the use of a FunctionDeclaration as a Statement results in code t=
hat is not reliably portable among implementations. It is recommended that =
ECMAScript implementations either disallow this usage of FunctionDeclaratio=
n or issue a warning when such a usage is encountered. Future editions of E=
CMAScript may define alternative portable means for declaring functions in =
a Statement context.

Also see section on functions in

There seem to be more browsers that treat function declarations in blocks a=
s straightforward extensions of the function hoisting semantics (unconditio=
nally) but Firefox does something different.

As I say in the above blog post, you have to have them in a browser but any=
thing other than trivial usage is unlike to be interoperable.


> -----Original Message-----
> From: es-discuss-bounces at [mailto:es-discuss-
> bounces at] On Behalf Of Michael Day
> Sent: Thursday, November 11, 2010 3:46 PM
> To: ES-Discuss
> Subject: Function declarations as statements
> Hi,
> In ECMAScript, function declarations are SourceElements, but not Statemen=
> This means that they can only occur at the top level, and may not be nest=
> inside a block.
> However, browsers support function declarations as statements, and many
> scripts on the web seem to make use of this ability, especially after the=
y have
> been minified.
> Is there a spec anywhere for how functions as statements should behave?
> Can they be rewritten to var + function expression, so that this:
> {
>      function f() { return 17 }
> }
> becomes this:
> {
>      var f =3D function() { return 17 }
> }
> When implementing non-standard features, it would be nice to do so in a
> standard manner :)
> Best regards,
> Michael
> --
> Print XML with Prince!
> _______________________________________________
> es-discuss mailing list
> es-discuss at

More information about the es-discuss mailing list