Skip to content

Instantly share code, notes, and snippets.

@wangtai
Created November 29, 2014 08:24
Show Gist options
  • Save wangtai/94de1b025e9ed123c4e9 to your computer and use it in GitHub Desktop.
Save wangtai/94de1b025e9ed123c4e9 to your computer and use it in GitHub Desktop.
(function() {
if ( typeof Object.prototype.uniqueId == "undefined" ) {
var id = 0;
Object.prototype.uniqueId = function() {
if ( typeof this.__uniqueid == "undefined" ) {
this.__uniqueid = ++id;
}
return this.__uniqueid;
};
}
})();
var obj1 = {};
var obj2 = new Object();
console.log(obj1.uniqueId());
console.log(obj2.uniqueId());
console.log([].uniqueId());
console.log({}.uniqueId());
console.log(/./.uniqueId());
console.log((function() {}).uniqueId());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment