Skip to content

Instantly share code, notes, and snippets.

@patrickfox
Created September 9, 2014 14:32
Show Gist options
  • Save patrickfox/766bf70cd01c122bf812 to your computer and use it in GitHub Desktop.
Save patrickfox/766bf70cd01c122bf812 to your computer and use it in GitHub Desktop.
$.get_named_guid() generates a globally unique ID(GUID) based on a unique reference of handle. This GUID can then be called up at a later point by passing in the handle.
$.get_named_guid = function(handle, get_new) {
var _base,
_name = "_" + handle;
get_new = get_new || false;
$.guid = $.guid || 0;
$.named_guids = $.named_guids || [];
_base = $.named_guids["_" + handle];
if (_base[_name] === null) {
_base[_name] = $.guid++;
}
if (!get_new) {
return $.named_guids[_name];
}
$.named_guids[_name] = ++$.guid;
return $.named_guids[_name];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment