Overriding Map/etc with get/set hooks?

Sam Tobin-Hochstadt samth at ccs.neu.edu
Tue May 21 07:19:22 PDT 2013

On Tue, May 21, 2013 at 6:52 AM, Anne van Kesteren <annevk at annevk.nl> wrote:
> On Tue, May 21, 2013 at 12:19 PM, Brendan Eich <brendan at mozilla.com> wrote:
>> Of course, coercing key type makes the API not Map. So if the
>> bi-directionality is important, this would be a custom Map-like class.
> I guess I also do not really get this. Sure JavaScript does not have a
> type system (yet?), but it seems that placing restrictions / coercion
> on input does not invalidate any of the properties of a map other than
> that there's a restriction on what goes in the map. To me that seems
> very much like a subset of a map and all generic functionality written
> around maps would work on such a map.

The following function returns true for all Maps M, Strings k, and JS values v:

function check(M, k, v) {
   return (v === M.get(k));

In fact, this is the essence of what Maps are about.  Your proposal
doesn't have this property. Therefore, it shouldn't be a Map.

The analogy to NodeList is actually valuable -- NodeLists are pretty
different from Arrays, but some of the array generics work on them. If
the problem is that the Map functions should be more generic, that's
something that could be fixed, but that doesn't mean we should pretend
that things are maps when they aren't.


More information about the es-discuss mailing list