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