Created
May 20, 2024 15:57
-
-
Save helabenkhalfallah/3be08466a32075b29c745ec515d9c90c to your computer and use it in GitHub Desktop.
Basic creation of a Proxy
This file contains hidden or 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 = { | |
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