Separating a Hash type from Object

Brendan Eich brendan at
Tue May 1 22:41:27 PDT 2007

On May 1, 2007, at 10:14 PM, Andrew Dupont wrote:

> Brendan Eich wrote:
>> I'm confused -- do you intend that foo#.toString name a property in
>> no namespace with identifier 'toString' in some object, or a property
>> in a hidden namespace with local name 'toString'?
> The latter was my interpretation. But you're saying that the #.  
> operator
> would simply look at the subset of an object's properties that are
> defined on the instance?

Yes -- hence the direct:: namespace conceit that lost to #. #[ #{.

> That's more reasonable than creating a whole new property  
> namespace. It
> doesn't solve the string coercion problem, though. Combining the #.
> operator with "use namespace intrinsic;" would, but that means the
> developer would have to *opt into* key safety.

The key safety problems you cite are (a) matching toString or another  
indirect (prototype-owned) property; (b) setting toString in the  
directly referenced object to some value not a toString function.  
You're right, #. addresses only (a).

To address (b) would seem to require opting in as you note, or  
changing the usual rules for hashes (objects created via #{...}) to  
look for methods in a special namespace (intrinsic, or perhaps  
function as in SpiderMonkey).

This is a fair amount of magic for the Hash class, and some of it  
(the function namespace) might want to be abstracted over any class,  
since E4X's XML class in SpiderMonkey wants the ability to access XML  
methods via, e.g., function::elements.

Leaving (b) unsolved without opt-in (use namespace intrinsic), we  
could avoid a Hash class with magic method lookup rules altogether,  
and add #. #[ #{ as shorthand, where obj#.ident, obj#[expr] ,  
obj#.ns::ident, and obj#.ns::[expr] would be variations on the  
corresponding unsharp (hash-free) operators, which would work on any  
kind of object by looking only in the directly referenced object, not  
any prototype.


More information about the Es4-discuss mailing list