
Proxy Pattern
This teaches you how to use JavaScript's Proxy object to intercept and control operations on objects like property access, assignment, and function calls. It's from patterns.dev and covers the fundamentals with the person object example, showing how to add validation, logging, and access control through get and set traps. The guide includes practical advice on using Reflect for cleaner code and is honest about the tradeoffs: proxies add overhead and shouldn't be used in performance critical paths. Good for learning when you actually need this pattern versus just using regular getters and setters. The validation examples are straightforward and the "when NOT to use" section is refreshingly direct about avoiding overengineering.
- skills.sh installs
- 627
- GitHub stars
- 258
- last updated
- Aug 21, 2026
Install
$ npx -y skills add patternsdev/skills --skill proxy-pattern --agent claude-codeInstalls into .claude/skills of the current project.
Files
Proxy Pattern
With a Proxy object, we get more control over the interactions with certain objects. A proxy object can determine the behavior whenever we're interacting with the object, for example when we're getting a value, or setting a value.
When to Use
- Use this when you need to add validation, formatting, notifications, or debugging to object access
- This is helpful for controlling and intercepting property gets and sets on objects
When NOT to Use
- In performance-critical hot paths where Proxy overhead on every property access matters
- When simple getter/setter methods or Object.defineProperty achieve the same validation with less indirection
- When the target objects are rarely accessed and the interception logic isn't needed
Instructions
- Create a
Proxywith a handler object defininggetandsettraps - Use the
Reflectobject within handlers for cleaner property access and modification - Add validation logic in the
settrap to ensure data integrity - Avoid using proxies in performance-critical code paths as they add overhead
Details
Sponsors
Details
- Repository
- github.com/patternsdev/skills
- Categories
- Backend & APIs, DevOps & CI/CD
- First seen
- Jun 3, 2026
More from patternsdev/skills
All 47- Flyweight Pattern626
- Mediator Pattern622
- Ai Ui Patterns2.2K
- React 20262.1K
- Dynamic Import1.7K
- Bundle Splitting1.7K
- Compression1.7K
- Loading Sequence1.7K
- Preload1.7K
- Import On Interaction1.6K
- Prefetch1.6K
- Import On Visibility1.6K
- Third Party1.6K
- Virtual Lists1.6K
- Route Based1.6K
- Tree Shaking1.6K
- Prpl1.6K
- Static Import1.6K
- Hooks Pattern1.2K
- React Composition 20261.2K
- Presentational Container Pattern1.2K
- React Render Optimization1.1K
- React Data Fetching1.1K
- Compound Pattern1.1K