javascript - Create a class extending from ES6 Map -


trying away custom get/set functionality on es6 maps. using babel transpile code es5.

chrome version 41.0.2272.101 m

class mymap extends map {     get(key) {         if (!this.has(key)) { throw new error(...); }         return super.get(key);     }      set(key) {         if (this.has(key)) { throw new error(...); }         return super.set(key);     } } 

not sure if got syntax wrong or i'm missing implementation of sort. following error:

method map.prototype.foreach called on incompatible reciever

babel explictly states not support extending built-in classes. see http://babeljs.io/docs/usage/caveats/#classes. reasons not quite simple "limitations in es5", however, since map not es5 feature begin with. appears implementations of map not support basic patterns such as

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

which babel generates in case. problem implementations of map including v8 overly restrictive , check this in map.set.call call precisely map, rather having map in prototype chain.

same applies promise.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -