-
-
Save OMGZui/90ebad309ea1547266e7a9a0a0bc26fd to your computer and use it in GitHub Desktop.
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 idol = { | |
name: 'Tom', | |
phone: 10086, | |
price: 1000000 | |
} | |
const agent = new Proxy(idol, { | |
get: function(target) { | |
return 'phone:10010'; | |
}, | |
set: function(target, key, value) { | |
if(key === 'price' ) { | |
if(value < target.price) throw new Error('low price'); | |
target.price = value; | |
} | |
} | |
}) | |
agent.phone; | |
agent.price = 100; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment