Overriding Map/etc with get/set hooks?

Tab Atkins Jr. jackalmage at gmail.com
Mon May 20 22:32:31 PDT 2013

On Mon, May 20, 2013 at 10:27 PM, Domenic Denicola
<domenic at domenicdenicola.com> wrote:
> Hmm, so that invariant wouldn't hold? I assume `has` would be similarly
> broken? Seems… not so  Map like, besides perhaps having some operations with
> the same name as Map's.
> Relevant: http://en.wikipedia.org/wiki/Liskov_substitution_principle

Let's ignore Liskov; I don't really care about subclassing, not least
because being strictly Liskov-pure makes most subclasses invalid.

The things I care about:

* when someone asks "is this Map-like?" in an appropriately idiomatic
JS way, they get a "yes" answer.
* when someone adds a new function to Maps in an appropriately
idiomatic JS way, the method also applies to this object
* when JS expands the set of built-in methods for Map, it also gets
applied to this object without me having to update my spec
* for all the existing Map methods, I get identical/equivalent methods
without having to manually redefine every single one of them

All of these are easy to do if this is just a Map (or has Map on its
prototype chain), but with a custom [[MapData]] whose behavior is
defined by my spec.


More information about the es-discuss mailing list