Skip to content

Instantly share code, notes, and snippets.

@mustafadalga
Created October 26, 2025 14:21
Show Gist options
  • Save mustafadalga/fa3c791dcf08908f4e123333da2afc5b to your computer and use it in GitHub Desktop.
Save mustafadalga/fa3c791dcf08908f4e123333da2afc5b to your computer and use it in GitHub Desktop.
Dynamic property creation | Proxy api
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