代理
{ //创建一个供应商的属性 let obj ={ time:'2017-03-11', name:'net', _r:123 } let monitor = new Proxy(obj,{ //拦截对象属性的读取 get(target,key){ return target[key].replace('2017','2020') }, set(target,key,val){ if(key === 'name'){ return target[key] = val }else{ return target[key] } }, has(target,key){ if(key === name){ return target[key] }else{ return false } }, deleteProperty(target,key){ if(key.indexOf('_')> -1){ delete target[key] return true }else{ return target[key] } } }) //读取属性 //console.log('get',monitor.time) //console.log('set',monitor.time,'2019') monitor.time = 2019 monitor.name = 'java' // console.log(monitor.name) // console.log('has','name' in monitor, 'time' in monitor) // console.log(monitor.time) delete monitor.time console.log(monitor) delete monitor._r console.log(monitor) }