Skip to content

Instantly share code, notes, and snippets.

@bga
Created October 9, 2010 16:11
Show Gist options
  • Save bga/618334 to your computer and use it in GitHub Desktop.
Save bga/618334 to your computer and use it in GitHub Desktop.
/*
Strong implementation must check that key is object,
hide weakMapN_ from enumeration, make it externally readonly and non deletable(Object.defineProperty, if presents),
but its bad for performance.
*/
(function($G)
{
var nextStoreKeyId = 0;
$G.WeakMap = function()
{
this.storeKeyName_ = 'weakMap' + nextStoreKeyId++ + '_';
};
$G.WeakMap.prototype._set = function(key, value)
{
key[this.storeKeyName_] = value;
};
$G.WeakMap.prototype._get = function(key)
{
return key[this.storeKeyName_];
};
$G.WeakMap.prototype._delete = function(key)
{
return delete key[this.storeKeyName_];
};
$G.WeakMap.prototype._has = function(key)
{
return this.storeKeyName_ in key;
};
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment