Created
August 22, 2011 07:41
-
-
Save gnab/1161868 to your computer and use it in GitHub Desktop.
JavaScript Module Namespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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