Maps and WeakMaps interoperability

Mark S. Miller erights at
Tue Dec 27 10:14:23 PST 2011

On Tue, Dec 27, 2011 at 7:15 AM, David Bruant <bruant.d at> wrote:

> Hi,
> Maps [1] and WeakMaps [2] are very similar in their API. Since neither
> proposal discusses how they should interact with each other, I was
> wondering what is supposed to happen when trying to use the API of one
> on the other.
> -----
> var m = new Map();
> var key = {};
> m.set(key, 37);
>, key); // ?
> -----
> Currently Chrome canary says "illegal access".
> Is it the behavior that is wished for the features?

That's what I wish. JS already has name-based polymorphism (as is typical
of scripting languages). Generic methods, such as those from
Array.prototype, are only appropriate when the actions of the generic
method can itself be fully described in terms of accessing other publicly
available properties by name-based lookup. In this case, get/set/has/delete
is the lowest level publicly available interface, and their semantics is
defined in terms of accessing internal encapsulated properties. In this
regard, they are more like the Date.prototype methods. The fact that
similar operations have the same names is all the polymorphism these need
or should have.

> My question obviously extends to Sets and any other such abstraction
> that would be considered in the future.


> David
> [1]
> [2]
> _______________________________________________
> es-discuss mailing list
> es-discuss at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list