Created
February 26, 2012 16:01
-
-
Save abozhilov/1917462 to your computer and use it in GitHub Desktop.
ID mapping
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
function getId () { | |
return getId.id++; | |
} | |
getId.id = 0; | |
function Foo() { | |
this.__id__ = getId(); | |
} | |
Foo.prototype.valueOf = function () { | |
return this.__id__; | |
}; | |
/* Example */ | |
var foo = new Foo(), | |
bar = {}; | |
bar[foo] = 20; | |
bar[foo]; //20 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment