Proxy and Reflect

A Proxy wraps an object and intercepts operations such as property reads, writes, function calls, and construction. Reflect provides standardized methods for performing many fundamental object operations.

Proxies power advanced abstractions such as reactive systems, validation layers, and virtualization, but they can also make behavior harder to reason about and may introduce performance overhead.

Intercepting Property Access
const user = {
  name: 'Suriya'
};

const proxy = new Proxy(user, {
  get(target, property, receiver) {
    console.log('Reading', property);
    return Reflect.get(target, property, receiver);
  }
});

console.log(proxy.name);
💡 The get trap intercepts property access and delegates the actual operation to Reflect.get.
Key Takeaways
  • Proxy intercepts fundamental object operations.
  • Reflect provides standard mechanisms for performing those operations.
  • Proxies are powerful but should be used intentionally.
Knowledge Check

What is a Proxy primarily used for?