Skip to content

Instantly share code, notes, and snippets.

@mcavaliere
Created December 22, 2015 19:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcavaliere/865a836c1830c3372e43 to your computer and use it in GitHub Desktop.
Save mcavaliere/865a836c1830c3372e43 to your computer and use it in GitHub Desktop.
var MyApp = {};
MyApp.namespace = function() {
var ln = arguments.length, i, value, split, x, xln, parts, object;
for (i = 0; i < ln; i++) {
value = arguments[i];
parts = value.split(".");
object = window[parts[0]] = Object(window[parts[0]]);
for (x = 1, xln = parts.length; x < xln; x++) {
object = object[parts[x]] = Object(object[parts[x]]);
}
}
return object;
};
// Shortcut alias
MyApp.ns = MyApp.namespace;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment