Skip to content

Instantly share code, notes, and snippets.

@pavelvasev
Created August 2, 2015 06:43
Show Gist options
  • Save pavelvasev/1d37390dfdd2dcba24ac to your computer and use it in GitHub Desktop.
Save pavelvasev/1d37390dfdd2dcba24ac to your computer and use it in GitHub Desktop.
_uniqueId method for js objects
(function() {
var id_counter = 1;
Object.defineProperty(Object.prototype, "__uniqueId", {
writable: true
});
Object.defineProperty(Object.prototype, "_uniqueId", {
get: function() {
if (this.__uniqueId == undefined)
this.__uniqueId = id_counter++;
return this.__uniqueId;
}
});
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment