Skip to content

Files

Latest commit

8e0d379 · Jan 20, 2025

History

History
27 lines (21 loc) · 815 Bytes

what_is_a_proxy_object.md

File metadata and controls

27 lines (21 loc) · 815 Bytes

What is a proxy object?

A Proxy object is used to define custom behavior for fundamental operations (e.g., property lookup, assignment, function invocation) on another object. It is used for tasks like validation, logging, or access control.

Example:

const person = {
  name: 'John'
};
const handler = {
  get: function(target, prop) {
    if (prop === 'name') {
      return 'Jane';
    }
    return prop;
  }
};
const proxyPerson = new Proxy(person, handler);
console.log(proxyPerson.name); // 'Jane'

Tags: basic, JavaScript, objects

URL: https://www.tiktok.com/@jsmentoring/photo/7458050469735320865