Created
May 15, 2015 04:04
-
-
Save kirnovak/806dceea894b3d8e2329 to your computer and use it in GitHub Desktop.
ns() - namespaces for javascript
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 ns (namespase) { | |
var parts = namespase.split('.'), | |
parent, | |
i; | |
if ( window.hasOwnProperty(parts[0]) === false ) { | |
window[parts[0]] = {}; | |
} | |
parent = window[parts[0]]; | |
parts = parts.slice(1); | |
for (i = 0; i < parts.length; i += 1) { | |
if (typeof parent[parts[i]] === 'undefined') { | |
parent[parts[i]] = {}; | |
} | |
parent = parent[parts[i]]; | |
} | |
return parent; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment