let number = 19
object.defindProperty(person,‘age’,{
value: 19,
enumberable: true,
writeable: true,
configurable: true,
})
object.defindProperty(person,‘age’,{
get:funcation(){
return number
})
})
let number = 18
let person = {
name: ‘zhangsan’,
sex: ‘男’
}
object.defindProperty(person,‘age’,{
get(){
return number
}
set(value){
number=value
}
})
数据代理:通过一个对象代理另一个对象中属性的操作。
let obj = {x:100}
let obj2 = {y:200}
object.definedProperty(obj2,‘x’,{
get(){
return obj.x
}
set(value){
obj.x = value
}
})