Skip to content

Instantly share code, notes, and snippets.

@abozhilov
Created February 26, 2012 16:01
Show Gist options
  • Save abozhilov/1917462 to your computer and use it in GitHub Desktop.
Save abozhilov/1917462 to your computer and use it in GitHub Desktop.
ID mapping
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