Skip to content

Instantly share code, notes, and snippets.

@xulapp
Created June 16, 2011 14:04
Show Gist options
  • Save xulapp/1029282 to your computer and use it in GitHub Desktop.
Save xulapp/1029282 to your computer and use it in GitHub Desktop.
var id = (function() {
var uid = 0;
var dic = Object.create(null);
var map = WeakMap();
return function id(obj) {
if (!(obj instanceof Object))
return obj in dic ? dic[obj] : dic[obj] = uid++;
if (map.has(obj))
return map.get(obj);
map.set(obj, uid);
return uid++;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment