Created
February 23, 2019 04:41
-
-
Save mythz/6a4a02358e6a63e8c1820709fe28b20f to your computer and use it in GitHub Desktop.
Minimal AMD define()
This file contains 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
var EXPORT = { vue: 'Vue' }; | |
window.define = function (name, deps, f) { | |
var anon = typeof name != "string"; | |
if (anon) { | |
f = deps; | |
deps = name; | |
} | |
if (typeof deps == "function") { | |
f = deps; | |
deps = []; | |
} | |
var args = []; | |
if (deps) for (var i=0,len=deps.length; i<len; i++) { | |
args[i] = require(deps[i]); | |
} | |
if (anon) { | |
f.apply(undefined,args); | |
} else { | |
exports[name] = f.apply(undefined,args); | |
if (EXPORT[name]) window[EXPORT[name]] = exports[name]; | |
} | |
}; | |
window.define.amd = { jQuery: true }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment