liveBook · Manning

Modularity

As explained in The Joy of JavaScript

A software design approach that structures a program as separate modules with well-defined responsibilities and interfaces.

Modularity structures JavaScript programs as separate areas of code with focused responsibilities and controlled access to data and behavior. It supports clear separation of concerns while offering several implementation choices rather than one mandatory object model. section 1.0 section 6.2

Before native module specifications, JavaScript code commonly shared the global space across script files. Function scope provided a practical boundary for isolating code, encapsulating data and behavior, and avoiding name clashes. section 6.2

Pre-module JavaScript uses several modular patterns:

  • Object namespaces organize related values under a shared object. section 6.2
  • Immediately Invoked Function Expressions create isolated scopes for code and private state. section 6.2
  • IIFE mixins, factory functions, and related patterns provide alternative ways to package behavior. section 6.2

A script without a module system

Instead of placing every application value in the global space, a script can use a function-created scope to keep implementation details isolated and expose only the behavior it needs to share. section 6.2

Modularity also connects to composability: decomposing code into fine-grained behavior makes functional code easier to compose and reason about. The boundary is therefore both organizational and behavioral. section 4.9

How The Joy of JavaScript covers it

How deep it goes
Explains pre-module patterns and their function-scope rationale, but stops short of detailed native module mechanics.
Examples
Uses global scripts, object namespaces, IIFEs, IIFE mixins, factory functions, and fine-grained functional decomposition.
What it assumes
Assumes JavaScript function scope and basic code organization while treating modular patterns as alternatives to global code.
What you can do after
Evaluate/understand how function scope and pre-module patterns isolate code and organize small JavaScript applications.
How it connects
Connects modularity to separation of concerns, encapsulation, function scope, and functional composition.

Also explained in

Compare how 10 books explain modularity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Joy of JavaScript. The section links point to the parts of the book it draws on.