Skip to content

Instantly share code, notes, and snippets.

@bergquist
Created October 23, 2012 12:51
Show Gist options
  • Save bergquist/3938571 to your computer and use it in GitHub Desktop.
Save bergquist/3938571 to your computer and use it in GitHub Desktop.
function namespace(namespaceString) {
var parts = namespaceString.split('.'),
parent = window,
currentPart = '';
for (var i = 0, length = parts.length; i < length; i++) {
currentPart = parts[i];
parent[currentPart] = parent[currentPart] || {};
parent = parent[currentPart];
}
return parent;
}
(function(Thing) {
//Thing is never null
})(namespace('Company.Namespace.Something.Thing'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment