Skip to content

Instantly share code, notes, and snippets.

@helabenkhalfallah
Created May 20, 2024 16:51
Show Gist options
  • Save helabenkhalfallah/677240209d26935c42876e992bfba749 to your computer and use it in GitHub Desktop.
Save helabenkhalfallah/677240209d26935c42876e992bfba749 to your computer and use it in GitHub Desktop.
Proxy Delete Example
const target = { name: 'Alice', age: 30 };
const handler = {
deleteProperty: function(target, prop) {
console.log(`Deleting property ${prop}.`);
delete target[prop];
return true;
}
};
const proxy = new Proxy(target, handler);
delete proxy.age; // Logs: Deleting property age.
console.log(target.age); // Output: undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment