Js proxy pattern

From Intense-Visions/harness-engineering · View interactive version

Js proxy pattern is an AI agent skill from the GitHub repository Intense-Visions/harness-engineering. > Intercept and control object property access with ES6 Proxy

How to use this skill

Skill file

JS Proxy Pattern

Intercept and control object property access with ES6 Proxy

When to Use

Instructions

  1. Create a handler object with trap methods (get, set, deleteProperty, etc.).
  2. Wrap the target object: const proxy = new Proxy(target, handler).
  3. In set traps, always call Reflect.set(target, prop, value) to apply the change and return its boolean result.
  4. In get traps, use Reflect.get(target, prop, receiver) to preserve prototype chain behavior.
  5. Use Reflect methods in traps — they mirror the Proxy trap API and ensure correct semantics.
const validator = {
  set(target, prop, value) {
    if (prop === 'age') {
      if (typeof value !== 'number' || value < 0) {
        throw new TypeError('Age must be a non-negative number');
      }
    }
    return Reflect.set(target, prop, value);
  },
};

const person = new Proxy({}, validator);
person.age = 30; // OK
person.age = -1; // Throws TypeError
  1. Avoid deeply nested Proxy wrapping — it compounds performance overhead on every property access.

Details

ES6 Proxy gives you a meta-programming hook at the object level. Traps intercept fundamental operations: get, set, has, deleteProperty, apply (for functions), and construct (for classes).

Trade-offs:

When NOT to use:

Related patterns:

Source

https://patterns.dev/javascript/proxy-pattern

Process

  1. Read the instructions and examples in this document.
  2. Apply the patterns to your implementation, adapting to your specific context.
  3. Verify your implementation against the details and edge cases listed above.

Harness Integration

Success Criteria

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.