Being universal with UMD
When the UMD specification was brought up, there was a lot of hype in the community. After all, the label universal already claims that UMD is the final module system – the one to rule them all. It tries to do this by supporting essentially three different kinds of JavaScript module formats:
- The classic way of doing things without a module system – that is, just by running JavaScript using
<script>
tags in the browser - The CommonJS format that is used by Node.js
- The previously discussed asynchronously loaded modules from the AMD specification
When you write a JavaScript file with the UMD specification in mind, you essentially make sure that every popular JavaScript runtime can read it. For instance, UMD works perfectly in Node.js and the browser.
To achieve this universality, UMD makes an educated guess regarding what module system can be used and selects it. For example, if a define
function is detected, then AMD...