Status

()

defect
RESOLVED DUPLICATE of bug 838540
5 years ago
5 years ago

People

(Reporter: aleth, Unassigned)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

If one tries to subclass a Map using Object.create, one runs into the following problem:

    function newMap(args) {
      Map.call(this, args);
    }
    newMap.prototype = Object.create(Map.prototype);
    newMap.prototype.constructor = newMap;
     
    let testmap = new newMap([["a",1],["b",2]]);
    print(testmap.get("b"));
    /*
    Exception: get method called on incompatible Object
    */ 

This despite newMaps being instances of Maps.

It's possible this is in fact not a bug, but if so, I'd like to understand why (and it probably should be explained on MDN too).
SpiderMonkey doesn't have ES6 subclassing support (and in particular support for @@create) yet.  So "this" in newMap ends up as a plain Object without the internal slots a Map needs.
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 838540
You need to log in before you can comment on or make changes to this bug.