Non-generic traps for non-generic objects (was: Overriding Map/etc with get/set hooks?)

Jason Orendorff jason.orendorff at gmail.com
Tue May 28 12:21:37 PDT 2013


On Tue, May 28, 2013 at 1:00 PM, Jason Orendorff
<jason.orendorff at gmail.com>wrote:

> I still think WebIDL might be the way to go. After all it is WebIDL
> support that makes your current spec language possible. But I have one more
> possibly productive suggestion, which I'll try to post today.
>

ES6 could provide a Mapping class, in a standard module, that works like
this:
  https://gist.github.com/jorendorff/5662673

All those methods are generic. Map would be a subclass of Mapping, with its
own fast non-generic methods shadowing the Mapping methods.

Benefits:

- User-defined classes that wish to expose a map-like API can subclass Map
(to inherit Map's implementation) or Mapping (to start fresh). Either way,
they support all Map methods without having to implement them all.

- New methods magically appear on all mappings when provided by the
implementation (or by a polyfill).

- No new hooks.

- instanceof would work (within a window).

- With minor WebIDL support, I think this satisfies Tab's use case of
making the DOM's map-like objects feel more like Maps with minimal
duplication of effort.

Some other languages do this. Python has collections.Mapping:
http://docs.python.org/2/library/collections.html#collections-abstract-base-classes

Java has AbstractMap:
http://docs.oracle.com/javase/6/docs/api/java/util/AbstractMap.html

But I think most languages do not provide anything like this; you just
write your own.

-j
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130528/07fb5a28/attachment.html>


More information about the es-discuss mailing list