Function declarations in statements

liorean liorean at
Sat Mar 17 07:18:00 PDT 2007

> On 17/03/07, Brendan Eich <brendan at> wrote:
> > The IE JScript bug should be fixed. It's just a deviation from the
> > standard, as far as I can tell.

On 17/03/07, Igor Bukanov <igor at> wrote:
> But then should SpiderMonkey aslo be fixed? Consider the following
> shell session:
> That is, in the first f() "if (false) var x;" defines x for the whole
> function yet in g() the function statement does not bind the local
> name until executed.
> For me JScript behavior is in fact more consistent. There both var and
> function statement is executed on the function entrance no matter
> where they are placed. Yet in SpiderMonkey only var has such property
> while function having an extra weiredness:
> Now try to explain to a new guy the logic behind this.

Not much logic behind that, actually. It's because var declarations
are statements and function declarations are source elements. So, var
declarations are specified to be allowed in flow control constructs,
while function declarations aren't, however inconsistent that may be.

The actual bug in JScript that we were talking about, though, is that
JScript initialise FunExpr in surrounding instead of contained scope:

    f=function fn(){return fn},
print(f()); // => null
David "liorean" Andersson

More information about the Es4-discuss mailing list