Created
October 9, 2010 16:11
-
-
Save bga/618334 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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