Created
June 16, 2011 14:04
-
-
Save xulapp/1029282 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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