Skip to content

Instantly share code, notes, and snippets.

@gnab
Created August 22, 2011 07:41
Show Gist options
  • Save gnab/1161868 to your computer and use it in GitHub Desktop.
Save gnab/1161868 to your computer and use it in GitHub Desktop.
JavaScript Module Namespace
var module = {};
module.namespace = function recurse(path, base) {
base = base || this;
if (!path) {
return base;
}
var name = path.substring(0, path.indexOf('.')) || path;
base[name] = base[name] || {};
return recurse(path.substring(name.length + 1), base[name]);
}
var c = module.namespace('a.b.c');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment