Maps and WeakMaps interoperability

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


On Tue, Dec 27, 2011 at 7:15 AM, David Bruant <bruant.d at gmail.com> 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);
>
> WeakMap.prototype.get.call(m, 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.
>

y.


>
> David
>
> [1] http://wiki.ecmascript.org/doku.php?id=harmony:simple_maps_and_sets
> [2] wiki.ecmascript.org/doku.php?id=harmony:weak_maps
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>



-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111227/01e9e12b/attachment.html>


More information about the es-discuss mailing list