liveBook · Manning

Module pattern

The module pattern is a software design pattern that encapsulates implementation details and state while exposing a controlled public interface.

How 2 Manning books explain it

Secrets of the JavaScript Ninja, Second Edition

A design pattern that encapsulates private implementation details behind a public interface, typically by returning an object from a closure or immediate function.

How it is used
Organizes growing JavaScript applications into reusable units with public operations and hidden implementation details.
How deep it goes
Works through IIFE scope, closure-backed private state, a returned interface, and augmentation with separately scoped internals.
Examples
Uses a browser click counter and a scroll-counting extension to show private state, public methods, and augmentation.
What you can do after
Build it from scratch with an IIFE, a returned interface object, and closure-preserved private state.

Read how Secrets of the JavaScript Ninja, Second Edition explains module pattern →

Functional Programming in JavaScript

A JavaScript encapsulation pattern that exposes a public API while keeping internal state and helper functions hidden.

How it is used
Packages functional JavaScript code into encapsulated modules with a deliberately limited public API.
How deep it goes
Explains IIFE encapsulation, closure access, private variables, exported methods, and reduced global references.
Examples
Uses a zip-code factory whose returned methods access hidden code and location variables.
What you can do after
Apply closures and IIFEs to build JavaScript modules with hidden state and exposed behavior.

Read how Functional Programming in JavaScript explains module pattern →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.