Created
November 30, 2011 15:10
-
-
Save jaguire/1409388 to your computer and use it in GitHub Desktop.
Simple javascript namespacing. Intended as code organization before being bundled for deployment.
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
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]]; | |
} | |
}; |
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
namespace('myApp.tasks'); | |
// ctor | |
myApp.tasks.myTask = function() { | |
var self = this; | |
// public function run | |
self.run = function () { } | |
// private function | |
function privateFunction() { }; | |
}; |
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
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