This is the module format you don't know you need until you need it. Write your module once and have it work in a CJS/NodeJs, AMD, YUI (v3+), or Browser Global environment.
- You are migrating from namespaced (err, globals) code to either AMD or CJS modules or both.
- You can't yet factor out browser globals but also need to test your code via NodeJS (e.g. Mocha).
- A single module format allowing you to target AMD, CJS/NodeJS, and legacy browser globals like
window.*
. - Allows multiple dependencies to be defined.
- Run unit tests via CLI/NodeJS runner (e.g. Mocha).
- Less pain while incrementally migrating to CJS/NodeJS or AMD modules.
- You give up the Java-like namespaces (e.g. com.company.package.module) -- meh, they are a mess anyway.
- This (UMD) isn't a standard; to be fair, neither is AMD (it's a convention with a well-defined spec).
- Non-trivial amount of boilerplate (and Ugly).
- umdjs/umd#1
- https://gist.github.com/1387943
- https://github.com/chaijs/chai/blob/master/chai.js#L1-11
- http://www.youtube.com/watch?v=TqX-CqYYwEc (skip to 17:00)
- RequireJs Exported Value
- AMD is Not the Answer (anti-amd)
- Simplicity and JavaScript modules (pro-amd)
- Building The Next SoundCloud (cjs+amd)