function hoisting like var
Ingvar von Schoultz
ingvar-v-s at comhem.se
Sun Jul 27 17:31:39 PDT 2008
Mike Shaver wrote:
> 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 meant that "[" would follow those rules, not "{". The rules I
sketched are definitely not usable for "{".
>> 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?
These are valid literals (immediately discarded, but valid
syntax):
if (true) [10, 20];
if (true) { [10, 20] };
Likewise valid:
if (true) 10;
> 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
> _______________________________________________
> Es4-discuss mailing list
> Es4-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es4-discuss
>
--
Ingvar von Schoultz
------- (My quirky use of capitals in code comes from my opinion that
reserved and predefined words should all start with lowercase, and
user-defined should all start with uppercase, because this will easily
and elegantly prevent a host of name-collision problems when things
like programming languages are upgraded with new labels.)
More information about the Es4-discuss
mailing list