Separating a Hash type from Object

Brendan Eich brendan at
Tue May 1 23:40:28 PDT 2007

On May 1, 2007, at 11:28 PM, Yuh-Ruey Chen wrote:

> As elegant as it is to use # for hashes, I'm not sure if a special
> syntax is needed for it, since I imagine it's usage would be  
> limited to
> only certain classes. It doesn't introduce any new functionality,  
> since
> we already have hasOwnProperty(). Perhaps a better way would be to  
> allow
> the author to override the "[]" and "." operator in some coherent way
> (the approach C++ and Python take).

Indeed, #. etc. is just a thought experiment. But just providing the  
ability to override . and [] wouldn't help so much without a default  
implementation -- it would force everyone wanting a hash unpolluted  
by Object.prototype to reinvent the wheel.

So let's say there's a standard Hash or Dictionary class, with  
operator static functions for . and []. Then the missing piece is  
initializer syntax. We've talked about the thin nature of any #{...}  
syntax, since

let myDict : Dictionary = {...};

could perhaps optimize to avoid constructing an Object instance, then  
converting it to the Dictionary type due to the type annotation on  
myDict (perhaps, because object initialiser evaluation in ES3 is  
observable if one wraps or overrides the Object constructor -- see  
the recent JSON security blog threads).

None of this is yet compelling enough, or coherent/general enough, to  
add to ES4. But work with me here...


More information about the Es4-discuss mailing list