Skip to content

Instantly share code, notes, and snippets.

@jarek-foksa
Created October 14, 2011 13:12
Show Gist options
  • Save jarek-foksa/1287050 to your computer and use it in GitHub Desktop.
Save jarek-foksa/1287050 to your computer and use it in GitHub Desktop.
var modules = {};
var _require;
var require = _require = function(scriptName) {
if (modules[scriptName] === undefined) {
console.error("require('" + scriptName + "'): file not found.");
return;
}
if (modules[scriptName].cached) {
return modules[scriptName].cached;
}
else {
return modules[scriptName]();
}
}
function module(scriptName, scriptContent) {
modules[scriptName] = function() {
var exports = {};
var require = function (scriptName) {
return _require(scriptName);
};
modules[scriptName].cached = exports;
(function() {
scriptContent(exports);
}).call(exports);
return exports;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment