Newly revised Section 10 for ES3.1.

Maciej Stachowiak mjs at
Thu Jul 10 17:17:30 PDT 2008

(Adding lists back to Cc, which I assume you meant to do)

On Jul 10, 2008, at 5:06 PM, Garrett Smith wrote:

> Authors who assume that the function was conditionally declared in IE
> and Opera (and who knows what else) would be making false assumption.

That's true, but what I have seen in practice is that code can end up  
depending on its false assumption being violated, or working by luck.  
For example, you see code like:

if (!isIE) {
     function somethingEssential() { }

where somethingEssential is then unconditionally called.

> If subsequent code relied on that false assumption, and produced
> intended results, it would be only by coincidence:
> if(!isIE && !isOpera) {
>  function a(){ return 0; }
> }
> else (
>  function a(){ return 1; } // IE gets here (coincidence unrelated to  
> else)
> }
> That would be very lucky programming, because if reversed, it would
> not produce the same results:
> if(isIE && isOpera) {
>  function a(){ return 1; }
> }
> else (
>  function a(){ return 0; } // IE gets here.(coincidence unrelated to  
> else)
> }
> FunctionDeclarations  are processed during variable instantiation,
> before code execution. IE and Opera (and probably other browsers)
> would always take the last one because in these environments, it would
> have the effect of:-
> function each(){ return 1; }
> function each(){ return 0; }
> if(isIE && isOpera) {
> }
> else {
> }
>> I do not know if it is possible to make a proposal that both is  
>> useful
>> and doesn't break the Web, within the premises of ES3.1. But it seems
>> to me that a proposal that is almost sure to break the Web would be
>> unacceptable under the ES3.1 assumptions, and locking it into a spec
>> without first doing some form of widespread testing seems like a
>> totally broken process.
> Is it possible to know how much breakage would occur?

I don't know, but I am pretty sure it would be a non-zero amount. I  
think it is up to proponents of this proposal to somehow demonstrate  
that the level of breakage would be low enough; the presumption should  
be in favor of compatibility.

> Web scripts that attempt to work across IE and Mozilla that use a
> FunctionDeclaration in a Block either exhibit a bug or get lucky. If
> FunctionStatement is used, it is not likely to be used on public
> websites.

I know it has been used on public web sites.

> A major US defense company I once dealt with had an app that was
> Mozilla-only (due to security concerns in IE). It is possible that
> they successfully used a FunctionStatement. It seems that making
> FunctionStatement a syntax error could cause a problem in a
> Mozilla-only application, where as making FunctionStatement a standard
> would not cause problems (unless the problem was that the original
> code so badly confused):-

The ES3.1 proposal (now withdrawn, I believe) would make your example  
below throw a runtime error, since the declaration of function a would  
have only block scope and so would be unavailable after the if  
statement completes.

> if(IE || Opera) {
>   function a(){ throw Error(); } // Error, but never reached.
> } else {
>   function a(){} // No Error
> }
> a();
> Implementation of the FunctionStatement would cause the Error to be
> thrown when IE or Opera were true. How likely is such code to exist?
> Such code is arguably already broken and would seem to perform against
> the author's intention in IE.
> That sounds to me to be:
> 1) Somewhat useful
> 2) Probably wouldn't cause much breakage (test).

I'm not sure what specifically you propose, but it would make me happy  
if block-level function declarations could be standardized in a way  
that tries to be compatible with existing practice. I realize this is  
a challenge.


More information about the Es4-discuss mailing list