Created
October 5, 2015 13:42
-
-
Save jeremypele/e4e4c5717875a1e2b5ea to your computer and use it in GitHub Desktop.
[JS] Modules namespacings
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
// Namespace creation method | |
function setNamespace (ns_string, ns) { | |
var parts = ns_string.split('.'), | |
parent = ns; | |
if (parts[0] === "App") { | |
parts = parts.slice(1); | |
} | |
var pl = parts.length; | |
for (var i = 0; i < pl; i++) { | |
//create a property if it doesnt exist | |
if (typeof parent[parts[i]] === 'undefined') { | |
parent[parts[i]] = {}; | |
} | |
parent = parent[parts[i]]; | |
} | |
return parent; | |
}; | |
//Create the namespace structure | |
var nsHelper = setNamespace('App.module.helpers'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment