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 how factory functions and the abstract factory pattern help you create objects flexibly and consistently in JavaScript.
- Observer and Pub/Sub Patterns in JavaScript
Master the observer pattern and its pub/sub variant for building decoupled, event-driven JavaScript applications.
- 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
Encapsulate interchangeable algorithms in separate objects and exchange them at runtime with the Strategy Design Pattern in JavaScript.
- Command Pattern
Learn the Command Design Pattern in JavaScript — turns requests into objects for undo/redo, queuing, and decoupling.
- State Machines in JavaScript
Learn how to implement state machines in JavaScript using XState — manage complex application logic with predictable, visualizable state transitions.
- Iterator and Generator Patterns
Learn to build custom iterables and generators in JavaScript with patterns for sequences, trees, and async data.
- 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.