Created
December 16, 2018 23:17
-
-
Save staydecent/92d89cf3bb6807ba2905d8a4dc6831fc to your computer and use it in GitHub Desktop.
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 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