chapter six
6 JavaScript’s module system
This chapter covers
- Programmatic module patterns
- Immediately-Invoked Function Expressions (IIFEs)
- The ECMAScript Module syntax and the new .mjs extension
- Dynamic vs static module systems
- Tree shaking and dead code elimination
- Principles of segregation and orthogonality
“Modular programming… removed limitless files”
Robert C. Martin (Uncle Bob)
The world of JavaScript development is changing frantically and the part of the language undergoing most of the change is its module system.
In these days of modern application development, we take the notion of modular programming for granted. The practice of breaking up our applications into different files and then linking them back together is already second nature to us. We don’t do this to avoid getting blisters in our fingers from endless scrolling, as Uncle Bob points out, we do this so that we can reason about and evolve different parts of our applications separately and without fear of breaking others.