What does "as if by the expression" mean in ES3?

Brendan Eich brendan at mozilla.org
Thu Jun 19 17:36:11 PDT 2008


On Jun 19, 2008, at 5:14 PM, Mark S. Miller wrote:

> For example, in ES3
>
> 11.1.4 Array Initializer
> ...
> 1. Create a new array as if by the expression new Array().
> ...
>
> The phrase "as if by the expression" followed by a literal snippet of
> code occurs repeatedly in ES3.

Did you see my message of 16 June, 10:50am?

https://mail.mozilla.org/pipermail/es4-discuss/2008-June/003020.html


> I know that ES4 prevents assignment to
> the various global variable names used by such code, but what about
> shadowing lexical variable definitions?


The wiki page, again, is:

http://wiki.ecmascript.org/doku.php?id=clarification:which_prototype

ES4 has gone with memoized original values *and* immutable type  
bindings, not name lookup with shadowing hazards, for a long time now.


> FF 2.0.0.14 on squarefree does
> seem to obey the literal reading of the ES3 spec -- that shadowing
> affects array and object literals:
>
> (function foo(){
>   function Array(){return Date;}
>   function Object(){return window;}
>   return new window.Array([1,2],{bar:3});
> })();
> function Date() { [native code] },[object Window]

Yes, SpiderMonkey followed ES3, as did other implementations, for  
many years. Try Firefox 3, it's out now and it uses the memoized  
original value. :-)


> Safari literals are not affected by such shadowing definitions. Which
> behavior does ES4 consider correct?

Lars wrote a spec and iterated on it in this list. Here's the third  
and (AFAIK) stable draft:

https://mail.mozilla.org/pipermail/es4-discuss/2008-April/002668.html

It too says

Unlike the case in ES3, the program can't shadow the binding for  
Object in order to invoke an alternative object constructor for  
object initializers.

NOTE   Though ES4 is incompatible with ES3 here, most real-world  
implementations of ES3 do not respect shadowing binding for Object  
when evaluating object initializers, and the incompatibility is of no  
consequence. See [8].

I know there's a lot of material to go through, between ES3, ES4  
drafts, and so on -- but it seems like we've been over this topic a  
lot, and recently too. In particular in my reply to you of three days  
ago :-/.

/be



More information about the Es4-discuss mailing list