Skip to content

Instantly share code, notes, and snippets.

@morganrallen
Created July 12, 2010 22:58
Show Gist options
  • Select an option

  • Save morganrallen/473195 to your computer and use it in GitHub Desktop.

Select an option

Save morganrallen/473195 to your computer and use it in GitHub Desktop.
(function(global) {
var config = false,
modules = [];
// setup single public namespace
var skel = global.skel = {
init: function(c) {
// put initial config in the public scope
config = c;
for(var i = 0; i < modules.length; i++) {
modules[i].run(config);
}
},
register: function(module) {
if(!module.run) {
throw new Error("Modules must provide at minimal a run() function");
};
modules.push(module);
if(module.register) {
modules.register(config);
};
}
}
})(this);
skel.init();
(function(skel) {
skel.register({
name: "skeleton",
run: function(config) {
// do some stuff
var x = 1;
return x;
}
});
})(skel);
@morganrallen
Copy link
Copy Markdown
Author

In this situation, run.js would be the last in the build.xml concatanation and gets this started. Modules register themselves if they need to do anything at runtime. init() then runs each of the modules after initing itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment