Proxy
# Proxy
const person = {
name: 'yk',
age: 18
}
const personProxy = new Proxy(person, {
get(target, property){
return property in target ? target[property] : 'default'
},
set(target, property, value){
if(property === 'age'){
if(!Number.isInterage(value)){
throw new TypeError(`${value} is not an int`)
}
}
target[property] = value
}
})