Created
May 20, 2024 16:51
-
-
Save helabenkhalfallah/677240209d26935c42876e992bfba749 to your computer and use it in GitHub Desktop.
Proxy Delete Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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