function hoisting like var

Mike Shaver mike.shaver at gmail.com
Sun Jul 27 16:55:57 PDT 2008


On Sun, Jul 27, 2008 at 7:51 PM, Ingvar von Schoultz
<ingvar-v-s at comhem.se> wrote:
>
>
> Igor Bukanov wrote:
>> eval('[]') is a valid and, in fact, useful ES3 code. Similarly eval('{[]}').
>
> Yes, and by my rules they both create and return a new, empty
> array, which is intuitively expected and compatible.

And the latter only does because the { is parsed as starting a block;
if it were to start out assuming a literal, you would get an illegal
object initializer.

> I get the impression that the parser always must start out
> assuming it's a literal, and backtrack if the syntax doesn't
> fit. The only exception would be at a spot where a literal
> isn't possible while a block is possible, but I don't think
> any such spot is possible.

if { block; }

would seem to be such a spot, no?  Regardless, I'm pretty sure ES3
compat requires that a statement starting with a { be taken as a block
and not a literal, with no backtracking.

js> {a:5, b:6}
typein:4: SyntaxError: invalid label:
typein:4: {a:5, b:6}
typein:4: ......^

Mike



More information about the Es4-discuss mailing list