Created
May 20, 2024 16:50
-
-
Save helabenkhalfallah/5ad2e8f49a3e9879b9761c87cd2f51bb to your computer and use it in GitHub Desktop.
Proxy Has 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 = { | |
has: function(target, prop) { | |
console.log(`Checking if property ${prop} is in target.`); | |
return prop in target; | |
} | |
}; | |
const proxy = new Proxy(target, handler); | |
console.log('name' in proxy); // Logs: Checking if property name is in target. Output: true | |
console.log('height' in proxy); // Logs: Checking if property height is in target. Output: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment