Skip to content

Instantly share code, notes, and snippets.

@helabenkhalfallah
Created May 20, 2024 16:53
Show Gist options
  • Save helabenkhalfallah/a253aa2476ed9fd81f3f8ff543b0ffce to your computer and use it in GitHub Desktop.
Save helabenkhalfallah/a253aa2476ed9fd81f3f8ff543b0ffce to your computer and use it in GitHub Desktop.
Proxy ownKeys Example
const target = { name: 'Alice', age: 30 };
const handler = {
ownKeys: function(target) {
console.log('Getting property keys.');
return Reflect.ownKeys(target);
}
};
const proxy = new Proxy(target, handler);
console.log(Object.keys(proxy)); // Logs: Getting property keys. Output: ['name', 'age']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment