[Bug 20019] Support subclassing ES6 Map
rossberg at google.com
Wed Nov 21 04:10:26 PST 2012
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
More information about the es-discuss