Skip to content

Instantly share code, notes, and snippets.

@helabenkhalfallah
Created May 20, 2024 16:50
Show Gist options
  • Save helabenkhalfallah/5ad2e8f49a3e9879b9761c87cd2f51bb to your computer and use it in GitHub Desktop.
Save helabenkhalfallah/5ad2e8f49a3e9879b9761c87cd2f51bb to your computer and use it in GitHub Desktop.
Proxy Has Example
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