Chapter 9. Creating modules and Bower components

 

This chapter covers

  • Asynchronous module definitions
  • CommonJS module system
  • Universal module definitions
  • Exposure of module functionality
  • Deployment of private and public components

When developing, we usually try to encapsulate specific functionality into reusable patterns, be it functions that have defined output on various input or objects and classes that combine state and behavior in a broader sense. The idea is to reuse the provided functionality and rely on the trustworthiness of a thoroughly specified and tested module.

Modules wrap functionality and provide an API to the outside program code. Other modules can consume this module’s API and use its functionality, without knowing the inner workings of this particular subprogram. Whereas modules structure functionality on a code level, components do so at an organizational level. Components are self-contained collections of modules, meaning that they provide functionality independent of their surrounding program code. As modules, they too offer a sense of reusability, this time between different projects. Developers should be able to add a component into their project in the form of a dependency and use this functionality without any substantial setup.

9.1. Asynchronous module definition

9.2. CommonJS and Universal Module Definition

9.3. Defining and deploying Bower components

9.4. Summary