Skip to content

Instantly share code, notes, and snippets.

@helabenkhalfallah
Last active May 20, 2024 16:20
Show Gist options
  • Save helabenkhalfallah/60053e204c2b858cf40dae10f83f36bc to your computer and use it in GitHub Desktop.
Save helabenkhalfallah/60053e204c2b858cf40dae10f83f36bc to your computer and use it in GitHub Desktop.
Basic Proxy Assignment (set)
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