Created
October 26, 2025 14:21
-
-
Save mustafadalga/fa3c791dcf08908f4e123333da2afc5b to your computer and use it in GitHub Desktop.
Dynamic property creation | Proxy api
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 = {} | |
| const handler = { | |
| get(target: Record<string, any>, property: string) { | |
| if (!Object.hasOwn(target, property)) { | |
| target[property] = `Dynamic property ${property}`; | |
| } | |
| return target[property] | |
| } | |
| } | |
| const proxy = new Proxy(target, handler) | |
| proxy.newProp = 333333 | |
| console.log(proxy.newProp, proxy.anotherProp, target) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment