patternsdev avatar

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-code

Installs 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 Proxy with a handler object defining get and set traps
  • Use the Reflect object within handlers for cleaner property access and modification
  • Add validation logic in the set trap 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
1aj-geddes avataraws-lambda-functionsaj-geddes/useful-ai-promptsCreate and deploy serverless functions using AWS Lambda with event sources, permissions, layers, and environment configuration. Use for event-driven computing w619skills.sh installs
2sickn33 avatarbackend-development-feature-developmentsickn33/antigravity-awesome-skillsbackend development feature development615skills.sh installs
3aj-geddes avatardatabase-query-optimizationaj-geddes/useful-ai-promptsImprove database query performance through indexing, query optimization, and execution plan analysis. Reduce response times and database load.593skills.sh installs
4recoupable avatarrecoup-apirecoupable/skillsCall the Recoupable API from the sandbox to fetch artist data, socials, organizations, research, documents and any other platform resource — and to invoke exter550skills.sh installs
5aj-geddes avatarpayment-gateway-integrationaj-geddes/useful-ai-promptsIntegrate payment gateways like Stripe, PayPal, and Square with backends for payment processing, subscription management, and webhook handling. Use when buildin529skills.sh installs
6sickn33 avatarmoodle-external-api-developmentsickn33/antigravity-awesome-skillsmoodle external api development526skills.sh installs