Created
June 20, 2016 17:18
-
-
Save darkoverlordofdata/f7aa5ce39132777b6ee6ea843de46ab8 to your computer and use it in GitHub Desktop.
AMD Compatible module self loader
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
/** | |
* AMD Compatible module loader | |
* | |
* @param root object | |
* @returns module loader function define | |
* | |
*/ | |
var define = (function (modules) { | |
return (name, deps, callback) => { | |
modules[name] = { id: name, exports: {} } | |
let args = [(name) => modules[name].exports, modules[name].exports] | |
for (let i = 2; i < deps.length; i++) | |
args.push(modules[deps[i]].exports) | |
callback.apply(modules[name], args) | |
} | |
}({})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment