function hoisting like var

Ingvar von Schoultz ingvar-v-s at
Sun Jul 27 19:41:52 PDT 2008

Richard Cornford wrote:
> Ingvar von Schoultz wrote:
>> Richard Cornford wrote:
> <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.
> And if I wanted that block scope this -
> eval("{[\n eval('var a = 1'),eval('var b = 2'),eval('a + b')\n]}");
> - will still give me an array (and side effects in the containing scope)?

Goodness, if the code generator writes that, it deserves to melt!

I'd say if you're aware of scoping blocks, and want to have a
scoping block, and despite this insist on separating with commas
rather than semicolons or bare newlines, well, then you deserve
the array that you get!

So the solution is to use semicolon or newline as separator,
preferably somewhere near the beginning.

Of course the real solution to all this is to use my original
{{ }} instead. You get used to them. And they're very easy to

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