Skip to content

Instantly share code, notes, and snippets.

@ruidlopes
Created August 3, 2011 15:18
Show Gist options
  • Save ruidlopes/1122890 to your computer and use it in GitHub Desktop.
Save ruidlopes/1122890 to your computer and use it in GitHub Desktop.
The perfect Javascript namespace creation Gist
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