ES4 draft: Map

Waldemar Horwat waldemar at
Fri Feb 29 16:52:34 PST 2008

> The optional /hashcode/ argument is a function that takes a key and 
> returns a numeric code for it. This code may be used to find 
> associations more quickly in the map. Two calls to the /hashcode/ 
> function on the same key value must return the same numeric code, and 
> the /hashcode/ function must always return the same numeric code for two 
> objects that compare equal by the /equals/ function. The default value 
> for /hashcode/ is the intrinsic global function |hashcode|.

Dost thou desire arbitrary numeric hashcodes or integral ones?

>       Map( object )
> When the |Map| class object is called as a function, it creates a new 
> |Map| object from |EnumerableId| to |*|, populating the new |Map| object 
> with the own properties of /object/.

Making Map(x) do something specialized like this seems like a bad idea.  If x is already a Map, I'd expect Map(x) to be idempotent and return x.

Should thou need this functionality, use a static method to get it.

Why does get return null instead of undefined when it fails to find an instance?

A version of get with a second parameter X that returns X when the value isn't present would be useful.

Need a clear() method that deletes all bindings.

The iteration protocol makes a copy before starting to iterate.  It might be implemented via copy-on-write but I'd like to see how expensive this is.


More information about the Es4-discuss mailing list