Last active
June 1, 2021 22:02
-
-
Save ryanburnette/cbb228681c4a288ec07c07fded0169f1 to your computer and use it in GitHub Desktop.
A universal definition pattern for JavaScript libraries. Supports require(), AMD, and browser.
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
;(function() { | |
function myModule() { | |
} | |
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { | |
module.exports = myModule; | |
} | |
else { | |
if (typeof define === 'function' && define.amd) { | |
define([], function() { | |
return myModule; | |
}); | |
} | |
else { | |
window.myModule = myModule; | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So that it won't interfere with module bundlers that do weird things with
window
.