Skip to content

Instantly share code, notes, and snippets.

@OMGZui
Last active October 21, 2022 13:01
Show Gist options
  • Save OMGZui/90ebad309ea1547266e7a9a0a0bc26fd to your computer and use it in GitHub Desktop.
Save OMGZui/90ebad309ea1547266e7a9a0a0bc26fd to your computer and use it in GitHub Desktop.
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