Skip to content

Instantly share code, notes, and snippets.

@staydecent
Created December 16, 2018 23:17
Show Gist options
  • Save staydecent/92d89cf3bb6807ba2905d8a4dc6831fc to your computer and use it in GitHub Desktop.
Save staydecent/92d89cf3bb6807ba2905d8a4dc6831fc to your computer and use it in GitHub Desktop.
const handler = {
get (obj, prop) {
if (prop in obj) {
if (typeof obj[prop] === 'object') {
return new Proxy(obj[prop], handler)
}
return obj[prop]
}
return new Proxy({}, handler)
}
}
const p = new Proxy({a: {b: {c: 1}}}, handler)
console.log(p.a.d, p.b, p.a.b.f, p.a.b.c, p.b.c.a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment