Created
August 3, 2011 15:18
-
-
Save ruidlopes/1122890 to your computer and use it in GitHub Desktop.
The perfect Javascript namespace creation Gist
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 namespace = (function(s) { | |
return function(ns) { | |
var current, scopes = ns.split("."), scope = s; | |
while (current = scopes.shift()) | |
scope = scope[current] = scope[current] || {}; | |
return scope; | |
}; | |
})(typeof global !== "undefined" ? global : window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment