Learn how to extend objects at runtime using the Decorator Pattern in JavaScript. Covers function decorators, class decorators, and the TC39 proposal.
Tutorial series
Javascript Design Patterns
10 tutorials — follow in order for the best learning path.
- The Decorator Pattern in JavaScript
- The Module Pattern in JavaScript
Learn how to use the module pattern to encapsulate code, create private state, and organize your JavaScript applications.
- Factory and Abstract Factory Patterns in JavaScript
Learn factory functions and the abstract factory pattern for creating objects flexibly in JavaScript, from simple factories to theme-based object families.
- Observer and Pub/Sub Patterns in JavaScript
Master the observer pattern and pub/sub for building decoupled, event-driven JavaScript applications with custom event emitters.
- The Singleton Pattern in JavaScript
Learn how to implement the Singleton pattern in JavaScript to ensure a class has only one instance with global access point.
- Strategy Pattern in JavaScript: Swap Algorithms at Runtime
Learn the Strategy Pattern in JavaScript: swap interchangeable algorithms at runtime with examples for payments, form validation, and shipping.
- Command Pattern in JavaScript: Encapsulation, Undo, and Queuing
Learn the Command pattern in JavaScript — turns requests into objects for undo/redo, queuing, and decoupling invokers from receivers in your design.
- State Machines in JavaScript Using XState
Learn how to implement state machines in JavaScript using XState: manage complex application logic with predictable, visualizable state transitions.
- Iterator and Generator Patterns in JavaScript
Learn iterator and generator patterns in JavaScript: custom iterables, lazy sequences, tree walkers, async data streams, and composable pipelines.
- The Proxy Design Pattern in JavaScript
Learn how to use the Proxy Design Pattern in JavaScript with ES6 Proxy for property validation, lazy loading, logging, and access control.