javascript - Is it possible to create a map without hardcoding the class name `Map`? -


i tried write utility function returns object same argument. function works fine classes, except es6 collection types such map:

function createinstanceofsameclass(arg) {     return object.create(object.getprototypeof(arg)); }  const m1 = new map(); const m2 = createinstanceofsameclass(m1); m2.set(1, "x"); //  uncaught typeerror: method map.prototype.set called on incompatible receiver #<map> 

the jsfiddle here.

um... can constructor way:

function create(obj){     return new obj.constructor(); } 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -