Last active
May 20, 2024 16:20
-
-
Save helabenkhalfallah/60053e204c2b858cf40dae10f83f36bc to your computer and use it in GitHub Desktop.
Basic Proxy Assignment (set)
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 = { message: "Hello, World!" }; | |
const handler = { | |
set: function(target, prop, value, receiver) { | |
console.log(`Setting property ${prop} to ${value}.`); | |
target[prop] = value; | |
return true; | |
} | |
}; | |
const proxy = new Proxy(target, handler); | |
proxy.message = "Hi"; // Logs: Setting property message to Hi. | |
console.log(target.message); // Output: Hi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment