Variable declarations inside with statements

Brendan Eich brendan at mozilla.org
Mon Jul 7 14:01:24 PDT 2008


On Jul 7, 2008, at 10:40 AM, Allen Wirfs-Brock wrote:

> Herman,
>
> I think you are correct, according to the ES3 standard.  The rules  
> of variable instantiation would host the variable to the scope  
> level of the function and initially set it to undefined.  However,  
> the algorithm you quoted, if executed inside a with statement  
> scoped to an object that includes a property with that identifier  
> name should assign the value to the property, not the hosted variable.
>

s/hosted/hoisted/g

> We need to check out all the common browser implementations to see  
> what the other ones do and we need to add the results to the our  
> discrepancies doc.  If a majority of browsers follow the JScript  
> lead in not implementing what the specification says we can  change  
> the spec. in ES3.1 (although, is isn’t clear that we have a good  
> specification mechanism available for describing the actual  
> behavior you observe).
>

There's no "follow[ing] JScript lead" here. The first JavaScript  
implementation in Netscape 2, and others followed it. The following  
page:

<script>
     var x = 42;
     var o = {x:33};
     with (o)
         var x = 21;
     alert('var x is ' + x + ', o.x is ' + o.x);
</script>

alerts "var x is 42, o.x is 21" in Firefox, Opera, and Safari.

> Of course, this is just further reinforcement of  why the ES 3.1  
> working group wants eliminate with statements from the ES3.1  
> “cautious” subset.
>

That shows poor reasoning. If 'with' in the wild never contains var  
declarations, but remains excessively popular, then the argument  
fails. But there is no argument from evidence here, AFAICT, only from  
aesthetic and best-practices ideas that may not be shared enough to  
be worth trying to legislate from the standard.

Also, please stop splitting strict mode preemptively. Let's argue  
about what strict mode should forbid, and why, sooner rather than  
later. Adding more modes won't get agreement by default. Cc'ing es4- 
discuss at mozilla.org.

/be




More information about the Es4-discuss mailing list