Skip to content

Instantly share code, notes, and snippets.

@danshearmur
Created April 29, 2013 14:25
Show Gist options
  • Save danshearmur/5481892 to your computer and use it in GitHub Desktop.
Save danshearmur/5481892 to your computer and use it in GitHub Desktop.
var module = (function () {
var hash = {};
function fetch (name) {
return hash[name];
}
fetch.create = function (name, thing) {
if (name in hash) {
throw new Error(name + ' is already a module');
}
return hash[name] = thing || {};
}
return fetch;
})();
var x = module.create('dan');
x.hello = "world";
console.log(module('dan').hello)
module.create('dan');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment