Created
January 6, 2011 22:43
-
-
Save bryanforbes/768752 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var guid = (function(){ | |
function hasUniqueNumber(){ | |
var docEl = document.documentElement, elem = document.createElement("div"); | |
return (typeof elem.uniqueNumber == "number" && typeof docEl.uniqueNumber == "number" && | |
elem.uniqueNumber != docEl.uniqueNumber); | |
} | |
var guid, last = 1; | |
if(hasUniqueNumber()){ | |
guid = function guid(obj){ | |
if(obj){ | |
if(typeof obj.uniqueNumber == "number"){ | |
return obj.uniqueNumber; | |
}else if(typeof obj.guid == "number"){ | |
return obj.guid; | |
} | |
return obj.guid = last++; | |
} | |
}; | |
}else{ | |
guid = function guid(obj){ | |
if(obj){ | |
if(typeof obj.guid == "number"){ | |
return obj.guid; | |
} | |
return obj.guid = last++; | |
} | |
}; | |
} | |
return guid; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment