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.

5.1. Working with code encapsulation

5.1.1. Understanding the Single Responsibility Principle

5.1.2. Information hiding and interfaces

5.1.3. Scoping and this keyword

5.1.4. Strict mode

5.1.5. Variable hoisting

5.2. JavaScript modules

5.2.1. Closures and the module pattern

5.2.2. Prototypal modularity

5.2.3. CommonJS modules

5.3. Using dependency management

5.3.1. Dependency graphs

5.3.2. Introducing RequireJS

5.3.3. Browserify: CJS in the browser

5.3.4. The Angular way

5.4. Understanding package management

5.4.1. Introducing Bower

5.4.2. Big libraries, small components

5.4.3. Choosing the right module system

5.4.4. Learning about circular dependencies

sitemap