Module pattern
The module pattern is a software design pattern that encapsulates implementation details and state while exposing a controlled public interface.
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
- objectuses · A computational object is a runtime entity or structured value representing data, state, or a resource, with properties or operations defined by its programming model.
- closureuses · A closure is a function or callable value together with access to bindings from the lexical environment in which it was created.
- immediately invoked function expressionuses · An immediately invoked function expression is a JavaScript function expression that is defined and executed immediately within the same syntactic construct, often creating an isolated scope.
- modulealternative to · A module is a distinct, bounded software unit that groups related code or functionality and provides an organizational or interaction boundary within a larger system.
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.

