Created
November 29, 2014 08:24
-
-
Save wangtai/94de1b025e9ed123c4e9 to your computer and use it in GitHub Desktop.
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() { | |
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