const person = new Proxy(
{
name: 'Tom',
age: 13
},
{
set: (item, key, value) => {
if(key === 'age') {
if(value > 18) {
throw new RangeError('age is too big')
} else {
item[key] = value
}
}
}
}
)
console.log(person.age = 12)
console.log(person.age = 19)