Map/Set/WeakMap constructor genericity

Jason Orendorff jason.orendorff at gmail.com
Fri Nov 2 08:54:25 PDT 2012


In the draft spec, you can basically turn any arbitrary object into a Map.

    var obj = new Date;
    Map.call(obj);
    Map.prototype.set.call(obj, "x", "y");
    assert(Map.prototype.get.call(obj, "x") === "y");

The same object can be a Set too. Why not?

    Set.call(obj, ["z"]);
    assert(Set.prototype.has.call(obj, "z"), true);

This is intended to make Map/Set/WeakMap subclassable, which is fine.  But
can we specify that without exposing Map initialization as a primitive that
users can apply to arbitrary objects?

As specified, a single object can have [[MapData]] and [[WeakMapData]] and
[[SetData]]. This is a pain to implement, and I don't see the benefit to
web developers.

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


More information about the es-discuss mailing list