Skip to content

Instantly share code, notes, and snippets.

@tobiasoberrauch
Forked from Couto/namespace.js
Created March 3, 2014 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobiasoberrauch/9329043 to your computer and use it in GitHub Desktop.
Save tobiasoberrauch/9329043 to your computer and use it in GitHub Desktop.
function namespace (ns) {
var parts = ns.split('.'),
root = window || this;
return (function walk (obj) {
if (!root[obj]) { root[obj] = {}; }
root = root[obj];
if (parts.length) { walk(parts.shift()); }
return root;
}(parts.shift()));
}
// Example
namespace('MyApp.Controllers.Menu').Sidebar = (function () {
// Code
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment