-
-
Save briancavalier/1254517 to your computer and use it in GitHub Desktop.
Universal JavaScript Module, supports AMD (RequireJS), Node.js, and the browser.
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
| // Define a global define() that works in the current environment | |
| (function(global) { | |
| var define; | |
| define = global.define; | |
| // If AMD, just use existing global.define | |
| if(!(typeof define === 'function' && define.amd)) { | |
| if(typeof require === 'function' && typeof module !== 'undefined' && module.exports) { | |
| //CommonJS | |
| define = function(deps, factory) { | |
| module.exports = factory.apply(this, deps.map(require)); | |
| }; | |
| } else { | |
| //Browser (regular script tag) | |
| define = function(name, deps, factory){ | |
| var d, i = 0, old = global[name], mod; | |
| while(d = deps[i]){ | |
| deps[i++] = this[d]; | |
| } | |
| global[name] = mod = factory.apply(global, deps); | |
| mod.noConflict = function(){ | |
| global[name] = old; | |
| return mod; | |
| }; | |
| }; | |
| } | |
| } | |
| global.define = define; | |
| })(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment