Last active
July 25, 2016 02:40
-
-
Save tennisonchan/2e6379b89c9f853bb8ef to your computer and use it in GitHub Desktop.
generate unique id for object without modifying Object.prototype #js
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 __next_objid = 1; | |
function objectId(obj) { | |
if (!obj) return obj; | |
if (!obj.__obj_id) obj.__obj_id = __next_objid++; | |
return obj.__obj_id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment