Created
April 16, 2020 19:12
-
-
Save hugows/60bf39d3bff2f9c94dbff7de2c87b60c to your computer and use it in GitHub Desktop.
proxy objects reminds me of lua's metatables
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 user = { | |
firstName: 'John', | |
lastName: 'Doe', | |
email: '[email protected]', | |
} | |
const handler = { | |
get(target, property) { | |
return target[property] || (property + "-not-found"); | |
} | |
} | |
const proxyUser = new Proxy(user, handler); | |
proxyUser.email |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment