Created
May 20, 2024 16:53
-
-
Save helabenkhalfallah/a253aa2476ed9fd81f3f8ff543b0ffce to your computer and use it in GitHub Desktop.
Proxy ownKeys 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 = { | |
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