the half map, half weak, fully cross platform solution
The status of ES6 Collections is messy right now. The proposal is still under discussion, few browsers already expose them with partial implementation and few methods are not possible to polyfill on older browsers and even on top of native, partially implemented, prototypes.
I am the author of the es6-collection polyfill and I will try to maintain them as frequently as possible. However, when there are these kind of inconsistencies I realize that doesn't make much sense to force a shim over unshimmable implementations so here I am with an alternative to my own polyfill.
This no strings attached utility is based over these, if you want personal, considerations:
m["delete"](key)every bloody time you want to delete a key in non ES5 yet browsers.
m.del(key)is semantically equivalent and does not break old browsers/engines syntax parsers
Accordingly, methods are similar to those defined by ES6 Collections specifications but might be different. Same difference you might have as example between
array.forEach() when it comes to callback parameters but as it is for
each() you can always trust your code, rather than current browser version ... deal?
In alphabetic order:
clear(void):HybridMapto remove all associated keys. Returns the instance itself
del(key:any):booleanto remove a key, if present. Returns true if it has been removed, false otherwise.
get(key:any):anyto retrieve a previously stored key. Returns the associated value, if any,
has(key:any):booleanto check if a generic key has been set before. Returns true in latter case, false otherwise
set(key:any, value:any):anyto associate a generic value with a generic key. Overwrites the previously set value, if any. Returns the value that has been set
Being quite new, feel free to propose something more if you believe is that needed or some change if you think is a real code/world improvement, thanks.
var HybridMap = require("../src/HybridMap.js").HybridMap;
npm install wruthen
test.htmlbut if your browser does not support
XMLHttpRequestvia file protocol then
npm install polpettaand then
polpettayou can go to http://localhost:1337/test.html now