Chapter 5 from JavaScript Application Design
Embracing modularity and dependency management
This chapter covers
-
Working with code encapsulation
-
Understanding modularity in JavaScript
-
Incorporating dependency injection
-
Using package management
-
Trying out ECMAScript 6
Now that we’re done with the Build First crash course, you’ll notice a decline in Grunt tasks, though you’ll definitely continue to improve your build. In contrast, you’ll see more examples discussing the tradeoffs between different ways you can work with the JavaScript code underlying your apps. This chapter focuses on modular design, driving down the code complexity of applications by separating concerns into different modules of interconnected, small pieces of code that do one thing well and are easily testable. You’ll manage complexity in asynchronous code flows, client-side JavaScript patterns and practices, and various kinds of testing in 8, respectively.
chapter 9.
Figure 5.1 shows how these bits and pieces of the second half of the book relate to each other.
Figure 5.1. Modularity, good architecture, and testing are fundamentals of designing maintainable applications.
Applications typically depend on external libraries (such as jQuery, Underscore, or AngularJS), which should be handled and updated by using package managers, rather than manually downloaded. Similarly, your application can also be broken down into smaller pieces that interact with each other, and that’s another focus of this chapter.