-
-
Save puffnfresh/4639452 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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