Skip to content

Instantly share code, notes, and snippets.

@monochromer
Created May 15, 2015 04:44
Show Gist options
  • Save monochromer/2c936734ea99b9540492 to your computer and use it in GitHub Desktop.
Save monochromer/2c936734ea99b9540492 to your computer and use it in GitHub Desktop.
Создание пространства имен в 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