[Bug 20019] Support subclassing ES6 Map

Axel Rauschmayer axel at rauschma.de
Wed Nov 21 05:04:59 PST 2012

Map and Set are the bare collection necessities and let us avoid the hazards of using objects as maps. Beyond that, I would want to see a holistically designed collections API. Tackling equality seems important: How do value objects fit into the picture? Will there be a per-type protocol? Or an operator (or similar) that one extends?

With modules and classes in ES6, we only need someone willing and able to implement such an API as an external library. As far as I’m aware, no such libraries exist. Which is surprising – IIRC several such libraries have been written for Java.


On Nov 21, 2012, at 13:10 , Andreas Rossberg <rossberg at google.com> wrote:

> On 20 November 2012 21:30, Tab Atkins Jr. <jackalmage at gmail.com> wrote:
>> On Tue, Nov 20, 2012 at 10:57 AM, Mark S. Miller <erights at google.com> wrote:
>>> I think adding a MultiMap API to ES7 is a good idea. Neither Map nor
>>> MultiMap should be a subclass of the other, since neither is an LSP
>>> subtype of the other.
>> When properly designed, as long as you interact with it only through
>> Map methods, a MultiMap can be an LSP subtype of Map.
>> [...]
>> The tricky part is dealing with .size and the iterator methods.  You
>> need .size to reflect the number of keys, not pairs, to be consistent
>> with Map.  But then .size doesn't match the length of the iterators
>> returned by .items() or .values(), unless both of these are changed to
>> only return the first value by default.  (They can't return an array
>> of values, because that's not what Map does.)
> If the multi map iterator returns the same key multiple times it
> already breaks the map contract. So you would need a separate
> iteration method for that. At that point, as Mark says, it is not
> clear what the benefit is.
> The proper approach would be to identify a common super class that
> identifies the commonalities. You could try to come up with a
> hierarchy of concepts, like they did for C++0X before it got
> downsized. But lacking types that hardly seems useful for JavaScript.
> /Andreas
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

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

More information about the es-discuss mailing list