Last active
November 12, 2022 20:18
-
-
Save Luisgustavom1/b89fb4929466d3f195809ed0105011de to your computer and use it in GitHub Desktop.
An example of new Proxy use
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 = { | |
name: 'luis' | |
} | |
const messages = { | |
hello: (userName) => `Ola ${userName}, seja bem vindo ao nosso sistema`, | |
goodBye: (userName) => `Até mais ${userName}, esperamos que volte sempre aqui`, | |
} | |
const messagesHandler = { | |
get(target, prop, receiver) { | |
return target[prop](user.name) | |
}, | |
} | |
const messagesProxy = new Proxy(messages, messagesHandler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment