I wouldn't call the following my favourite snippet; but one that came to my mind after I read your question. So might as well share it here. :) When I am building something simple, and want globally-unique identifiers for my objects, the following function does it for me.
function createGUID() {
function S4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4();
}
var guid = createGUID();
Why don't you use UUID4? en.wikipedia.org/wiki/Universally_unique_identifi…