Open Hongbusi opened 2 years ago
const obj = {};
Object.defineProperty(obj, 'data', {
get(){
return data
},
set(newVal) {
onsole.log('我改变了')
data = newVal;
},
});
var obj = {};
Object.defineProperties(obj, {
a: {
configurable: true, //表示该属性描述符可以被改变(默认为false)
get: function() {
console.log('get: ',a)
return a
},
set: function(newValue) {
a = newValue;
console.log('set: ',a)
}
},
b: {
configurable: true,
get: function() {
console.log('get: ',b)
return b;
},
set: function(newValue) {
b = newValue;
console.log('set: ',b)
}
}
})
const newObj = new Proxy({},{
get: function(obj, prop) {
return prop in obj ? obj[prop] : null;
},
set(newVal){
console.log(newVal)
console.log('我改变了')
return true
}
});