Created
October 22, 2012 09:07
-
-
Save qmmr/3930514 to your computer and use it in GitHub Desktop.
JavaScript: Module Pattern
This file contains hidden or 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(string) { | |
var parts = string.split('.'), | |
parent = APP, | |
i; | |
if (parts[0] === 'APP') { | |
parts = parts.slice(1); | |
} | |
for (i = 0; i < parts.length; 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