Skip to content

Instantly share code, notes, and snippets.

@jaguire
Created November 30, 2011 15:10
Show Gist options
  • Save jaguire/1409388 to your computer and use it in GitHub Desktop.
Save jaguire/1409388 to your computer and use it in GitHub Desktop.
Simple javascript namespacing. Intended as code organization before being bundled for deployment.
function namespace(path) {
var root = window;
var names = path.split('.');
for (i = 0; i < names.length; i++) {
root[names[i]] = root[names[i]] || {};
root = root[names[i]];
}
};
namespace('myApp.tasks');
// ctor
myApp.tasks.myTask = function() {
var self = this;
// public function run
self.run = function () { }
// private function
function privateFunction() { };
};
var task = new myApp.tasks.myTask();
task.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment