Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Создание пространства имен в js
var APP = APP || {};
APP.namespace = function (ns_string) {
var parts = ns_string.split('.'),
parent = APP,
i, len;
if (parts[0] === "APP") {
parts = parts.slice(1);
}
for (i = 0, len = parts.length; i < len; 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
You can’t perform that action at this time.