function hoisting like var

Brendan Eich brendan at mozilla.org
Sat Jul 26 01:15:49 PDT 2008


On Jul 26, 2008, at 4:03 AM, Ingvar von Schoultz wrote:

> waldemar at google.com wrote:
>> Ingvar von Schoultz wrote:
>>> waldemar at google.com wrote:
>>>> I'm trying to keep the language relatively simple.
>>> You can't get away from supporting this:
>>>
>>>     {
>>>         function a(){}
>>>         var b = a;
>>>     }
>>
>> What do you mean?  This is a syntax error in both ES3 and ES3.1.
>
> It works fine in Firefox 2, Konqueror 3, Opera 9, Internet
> Explorer 6, and server-side Rhino with JavaScript 1.6.

Waldemar meant precisely what he wrote: ES3 and draft ES3.1 -- the  
specifications, not random JS implementations.

> Five platforms out of five. Can you throw a syntax error here
> and claim to be compatible?

The implementations are not compatible. Please see the earlier es4- 
discuss thread with subject "Function declarations in statements" at:

https://mail.mozilla.org/pipermail/es4-discuss/2007-March/ 
thread.html#527


>>
>> It does not already exist in ES3 or ES3.1.
>
> It exists on platforms as described above. I assumed that ES4
> would be compatible.

No, because it is impossible to be compatible with conflicting  
extensions to ES3 that browsers have implemented. The conflicts and  
undesirable intersection semantics are why ES4 proposes, and ES3.1  
considered but deferred, block-scoped functions that must be direct  
children of braced blocks. This requires opt-in versioning, which is  
why ES3.1 deferred it.

/be

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20080726/a899629a/attachment-0002.html 


More information about the Es4-discuss mailing list