Recently I’ve been playing around a lot with JavaScript modules. The particular use case I’ve been thinking about is the creation of a large complex JavaScript library in a modular and sensible way. JavaScript doesn’t really do this very well. It does it so poorly, in fact, that a sizeable number of projects are all done in a single file. I did fine a number that used file concatenation to assemble the output scrpit, but this seems like a stone-age technique to me.
This led me to look at the two competing JavaScript module techniques: Asynchronous Module Definition (AMD) and CommonJS (CJS). AMD is the technique used in RequireJS) and CommonJS is the technique used by nodejs.