A basic module loader in 65 bytes
Add the code:
var moduleLoader = (function(a){return function(b,c){return c?(a[b]=c()):a[b]}})({});
Define a module:
moduleLoader('die', function() {
// modules are functions that return what people will get when they ask for your module
return function() {
Math.floor(Math.random() * 5) + 1;
};
});
Use your module:
var getRoll = moduleLoader('die');
console.log(getRoll());
Smaller version: