Create a class extending from ES6 Map

后端 未结 5 1175

Trying to get away with custom get/set functionality on ES6 Maps. Currently using Babel to transpile my code to ES5.

Chrome Version 41.0.2272.101 m

5条回答
  •  北海茫月
    2021-01-04 01:20

    Babel explictly states they do not support extending built-in classes. See http://babeljs.io/docs/usage/caveats/#classes. The reasons are not quite as simple as "limitations in ES5", however, since Map is not an ES5 feature to begin with. It appears that implementations of Map do not support basic patterns such as

    Map.prototype.set.call(mymap, 'key', 1);
    

    which is essentially what Babel generates in this case. The problem is that implementations of Map including V8 are overly restrictive and check that the this in the Map.set.call call is precisely a Map, rather than having Map in its prototype chain.

    Same applies to Promise.

提交回复
热议问题