function hoisting like var

Ingvar von Schoultz ingvar-v-s at
Sun Jul 27 18:15:49 PDT 2008

Richard Cornford wrote:
> Ingvar von Schoultz wrote:
>> Igor Bukanov wrote:
>>> 2008/7/28 Ingvar von Schoultz wrote:
> <snip>
>>>>> Any of this can be a valid ES3 code as [] always means an
>>>>> array literal.
>>>> I get the impression that disambiguation would be easy.
>>> 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.
> Are you saying that a block then may never be empty as a syntax
> rule? ES 3 blocks are allowed to be empty and I bet there are
> examples where blocks contain nothing but an IE/JScript
> conditional comment and so are going to be interpreted as
> being empty by other ES 3 implementations. (Comments are
> allowed inside array literal definitions at present).

Does it matter whether it's interpreted as an empty block or
an empty discarded array?

>> When I said that an array is a comma-separated list of values,
>> the fact that I left out the empty and the single-value cases
>> didn't mean that they should be seen as blocks! I just didn't
>> want to write a lengthy, exhaustive full grammar...
> <snip>
> {
>    1,2,3,4,5
> }
> - is a valid ES 3 Program (even if a pointless one); A Block
> statement containing an Expression statement (with automatic
> semi-colon insertion making the Expression statement
> into - 1,2,3,4,5; -).
> eval('{1,2,3,4,5}') - results in the value 5, while -
> eval('[1,2,3,4,5]') - returns a 5 element array.

Yes. And if the rules for "{" remain unchanged, and "[" starts out
assuming it's a literal, you get the same result with my rules.

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