Skip to content

Instantly share code, notes, and snippets.

Created Jul 30, 2020
What would you like to do?
// Use Proxy object and handler to create a new property on the fly
let Auto = () =>
// Proxy() object of JavaScript
new Proxy({}, {
// Handler checks if prop exits
// otherwise, creates it
get: (obj, prop) =>
prop in obj
? obj[prop]
: obj[prop] = Auto()
// Create only TOP level
let univ = Auto();
// Now assign to deeper level = "A+";
// Bingo! It works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment