Skip to content

Instantly share code, notes, and snippets.

@matthewp
Created January 5, 2017 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewp/81199932db5e1e487a2ea6a15983ac73 to your computer and use it in GitHub Desktop.
Save matthewp/81199932db5e1e487a2ea6a15983ac73 to your computer and use it in GitHub Desktop.
Map shim
if(typeof Map !== "function") {
var bid = typeof Symbol === 'function' ? Symbol('bid') : '__bid',
bidCnt = 1;
function BID(obj){
var type = typeof obj;
if(type === 'string' || type === 'number')
return obj;
var id = obj[bid];
if(!id) {
Object.defineProperty(obj, bid, {
value: id++,
enumerable: false,
writable: false,
configurable: false
});
}
return id;
}
function Map(){
this.k = {};
}
Map.prototype.set = function(key, value){
var id = BID(obj);
this.k[id] = value;
};
Map.prototype.get = function(key){
return this.k[BID(key)];
};
Map.prototype.delete = function(key){
delete this.k[BID(key)];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment