Created
July 12, 2010 22:58
-
-
Save morganrallen/473195 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(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); |
This file contains hidden or 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
skel.init(); | |
This file contains hidden or 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(skel) { | |
skel.register({ | |
name: "skeleton", | |
run: function(config) { | |
// do some stuff | |
var x = 1; | |
return x; | |
} | |
}); | |
})(skel); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.