Why can't I extend an ES6 Map? Here's my code:
class M extends Map {}
let m = new M();
m.set('key','val');
Running it on the Babel "Try It Out" page, I get this:
Method Map.prototype.set called on incompatible receiver [object Object]
There are a couple other questions that this one seems to duplicate (Create a class extending from ES6 Map and Inheriting from Set.prototype), but I think this is a different question. Maybe I'm being dense, but I can't tell from those whether my extremely simple example ought to work or not. Are the askers of those two questions trying to do something weird in their Map (or Set) extensions? Or, as seems to be the case from my example, is it just impossible to do anything useful by extending Map? (Because what would the point of extending it be if you can't inherit one of its most basic methods?) But if it is impossible to do anything useful with it, why is it allowed? Is there something I could be doing wrong in this tiny example? Or am I just not getting the point of why someone would want to extend Map.
Oh, and I realize I haven't shown here why I want to extend map. I'll tell you: I don't want to change any of its existing functionality, I just want to add additional methods--but not to the Map prototype, just to my own subclass.