Skip to content

Instantly share code, notes, and snippets.

@parhammmm
Created June 4, 2012 22:54
Show Gist options
  • Save parhammmm/2871333 to your computer and use it in GitHub Desktop.
Save parhammmm/2871333 to your computer and use it in GitHub Desktop.
Namespace example
// Creating a namespace
var chat = {
// Create this closure to contain the cached modules
module: function() {
// Internal module cache.
var modules = {};
// Create a new module reference scaffold or load an
// existing module.
return function(name) {
// If this module has already been created, return it.
if (modules[name]) {
return modules[name];
}
// Create a module and save it under this name
return modules[name] = { Views: {} };
};
}()
};
//Defining a module in the namespace
(function(Friend) {
})(chat.module("friend"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment