Created
December 6, 2012 01:45
-
-
Save giuliandrimba/4221198 to your computer and use it in GitHub Desktop.
JavaScript: namespace helper
This file contains 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
function namespace(name) | |
{ | |
var namespaces = name.split("."); | |
var name = ""; | |
function getName(parent) | |
{ | |
if(namespaces.length > 0) | |
{ | |
name = namespaces.shift(); | |
if(!parent[name]) | |
{ | |
parent[name] = {} | |
} | |
return getName(parent[name], namespaces) | |
} | |
else | |
{ | |
return parent; | |
} | |
} | |
return getName(window); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some functional code this time:
Testing (at window)
More (custom base)