Skip to content

Instantly share code, notes, and snippets.

@jeremypele
Created October 5, 2015 13:42
Show Gist options
  • Save jeremypele/e4e4c5717875a1e2b5ea to your computer and use it in GitHub Desktop.
Save jeremypele/e4e4c5717875a1e2b5ea to your computer and use it in GitHub Desktop.
[JS] Modules namespacings
// 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