Skip to content

Instantly share code, notes, and snippets.

@tennisonchan
Last active July 25, 2016 02:40
Show Gist options
  • Save tennisonchan/2e6379b89c9f853bb8ef to your computer and use it in GitHub Desktop.
Save tennisonchan/2e6379b89c9f853bb8ef to your computer and use it in GitHub Desktop.
generate unique id for object without modifying Object.prototype #js
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