Created
February 24, 2020 07:11
-
-
Save takahashi-h5/320d6ec6399b4b40a512503e1d3e68ef 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 obj = { | |
name: 'yamada', | |
age: 17 | |
}; | |
const handler = { | |
set: function(target, prop, value) { | |
console.log(value) | |
target[prop] = value.toUpperCase() | |
}, | |
get: (target, prop)=> { | |
console.log(target[prop]) | |
return target[prop].toUpperCase() | |
} | |
} | |
const proxy = new Proxy(obj, handler) | |
proxy.name = 'takahashi' // ここでsetが実行される | |
console.log(proxy.name) // ここでgetが実行される |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment