Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Forked from liammclennan/gist:4639397
Last active December 11, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puffnfresh/4639452 to your computer and use it in GitHub Desktop.
Save puffnfresh/4639452 to your computer and use it in GitHub Desktop.
(function(global) {
global.def = function define(name, dependencies, moduleFactory) {
global.amdModules = global.amdModules || {};
if (Object.prototype.toString.call(dependencies) != '[object Array]' && typeof dependencies !== 'function')
throw new Error('dependencies must be an array. moduleFactory must be a function.');
global.amdModules[name] = {
'moduleFactory': moduleFactory || dependencies,
'dependencies': typeof (moduleFactory) === 'undefined' ? [] : dependencies
};
};
global.req = function require(name) {
var module = global.amdModules[name],
deps = [];
if (typeof module === 'undefined') {
throw "Module " + name + " could not be found";
}
if (module.cached) return module.cached;
for (var i = 0; i < module.dependencies.length; i++) {
deps.push(requireAmd(module.dependencies[i]));
}
module.cached = module.moduleFactory.apply(this, deps);
return module.cached;
};
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment