Created
August 2, 2015 06:43
-
-
Save pavelvasev/1d37390dfdd2dcba24ac to your computer and use it in GitHub Desktop.
_uniqueId method for js objects
This file contains 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
(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