Skip to content

Instantly share code, notes, and snippets.

@tcorral
Created October 8, 2011 22:08
Show Gist options
  • Save tcorral/1272955 to your computer and use it in GitHub Desktop.
Save tcorral/1272955 to your computer and use it in GitHub Desktop.
Function that creates a namespace, from a string, to be used in your application.
function namespace(sNamespace)
{
var oObj = window;
var aElements = sNamespace.split(".");
var nElement = 0;
var nLenElements = aElements.length;
var sElement = null;
for(; nElement < nLenElements; nElement++)
{
sElement = aElements[nElement];
oObj = typeof oObj[sElement] !== 'undefined' ? oObj[sElement] : oObj[sElement] = {};
}
try
{
return oObj;
}finally
{
oObj = aElements = nElement = nLenElements = sElement = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment