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 http://blogs.msdn.com/b/ie/archive/2010/08=
/25/chakra-interoperability-means-more-than-just-standards.aspx=20

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.

Allen
=20

> -----Original Message-----
> From: es-discuss-bounces at mozilla.org [mailto:es-discuss-
> bounces at mozilla.org] On Behalf Of Michael Day
> Sent: Thursday, November 11, 2010 3:46 PM
> To: ES-Discuss
> Subject: Function declarations as statements
>=20
> Hi,
>=20
> In ECMAScript, function declarations are SourceElements, but not Statemen=
ts.
> This means that they can only occur at the top level, and may not be nest=
ed
> inside a block.
>=20
> 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.
>=20
> Is there a spec anywhere for how functions as statements should behave?
>=20
> Can they be rewritten to var + function expression, so that this:
>=20
> {
>      function f() { return 17 }
> }
>=20
> becomes this:
>=20
> {
>      var f =3D function() { return 17 }
> }
>=20
> When implementing non-standard features, it would be nice to do so in a
> standard manner :)
>=20
> Best regards,
>=20
> Michael
>=20
> --
> Print XML with Prince!
> http://www.princexml.com
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list