Skip to content

Instantly share code, notes, and snippets.

@helabenkhalfallah
Created May 20, 2024 15:57
Show Gist options
  • Save helabenkhalfallah/3be08466a32075b29c745ec515d9c90c to your computer and use it in GitHub Desktop.
Save helabenkhalfallah/3be08466a32075b29c745ec515d9c90c to your computer and use it in GitHub Desktop.
Basic creation of a Proxy
const target = { message: "Hello, World!" };
const handler = {
get: function(target, prop, receiver) {
console.log(`Property ${prop} was accessed.`);
return Reflect.get(target, prop, receiver);
}
};
const proxy = new Proxy(target, handler);
console.log(proxy.message); // Logs: Property message was accessed. Output: Hello, World!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment