Maps and WeakMaps interoperability

David Bruant bruant.d at gmail.com
Tue Dec 27 10:29:12 PST 2011


Le 27/12/2011 19:14, Mark S. Miller a écrit :
> On Tue, Dec 27, 2011 at 7:15 AM, David Bruant <bruant.d at gmail.com
> <mailto: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.
Very interesting point.

Currently, the Date.prototype method throw a TypeError (ES5.1 - 15.9.5
introductory section). The same is probably expected when trying map
operations on weakmap (etc.) ?

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111227/04b645c8/attachment-0001.html>


More information about the es-discuss mailing list