Created — forked from creationix/module.js

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View module.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
defs = {};
modules = {};
function define(name, fn) {
defs[name] = fn;
}
function require(name) {
console.log("Loading " + name);
if (modules.hasOwnProperty(name)) return modules[name];
if (defs.hasOwnProperty(name)) {
var fn = defs[name];
defs[name] = function () { throw new Error("Circular Dependency"); }
return modules[name] = fn();
}
throw new Error("Module not found: " + name);
}
View module.js
1 2 3 4 5 6 7 8 9 10 11
define('foo', function () {
return 42;
});
define('mymod', function () {
return {
stuff: "goes here",
"and here": require('foo')
};
});
 
var MyMod = require('mymod');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.