ES4 draft: Name

Brendan Eich brendan at mozilla.org
Thu Mar 13 17:10:09 PDT 2008


On Mar 13, 2008, at 4:05 PM, Lars Hansen wrote:
>
>> Why does valueOf do a toString on the Name?
>
> Entirely because the original spec (on the wiki) required it.  I  
> suspect
> this is the wrong design (and I think even Brendan, who wrote it up,
> questioned it, because it's left as an open issue on the wiki);

The motivation there was to masquerade Name instances as strings to  
ES3 code that did

   for (var i in es4obj) {
     ... something assuming i is a string per ES3 here ...
   }

It was necessary to override valueOf and toString, since when this  
proposal was written we believed that for-in loops over objects with  
namespaced properties should iterate i over Name objects where  
necessary to distinguish such properties from those identified by  
names in no namespace.

We now are converging on hiding all namespaced properties from for-in  
enumeration, which is great. This change does not eliminate the need  
for Name objects in ES4, but it does mean that they may not need to  
masquerade as Strings via subtyping, for backward compatibility. So  
we should reconsider all the String hacks in Name.es in this light.

> the
> ActionScript implementation of the E4X "QName" valueOf method returns
> 'this'; that is probably the right behavior here as well.

E4X's QName prototype valueOf is not specified, so that method is  
delegated to Object.prototype.valueOf, which returns this.

/be




More information about the Es4-discuss mailing list