-
-
Save arboleya/4465612 to your computer and use it in GitHub Desktop.
Simple namespace definer.
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
/* | |
USAGE: | |
# at window | |
ns( 'my.namespace' ).MyClass = ... | |
# at app obj | |
var app = {} | |
ns( 'my.namespace', app ).MyClass = ... | |
*/ | |
function ns( ns, base ) | |
{ | |
var n, b = base || window, r = /[^\.]+/g; | |
while( (n = r.exec( ns ) ) != null ) | |
b = b[n[0]] || (b[n[0]] = {}); | |
return b; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Testing (default = at window)
More (custom - inside app obj)