SOURCE

const obj={
    name:"zhangsan",
    age:18,
    sex:"nan"
}
Object.keys(obj).forEach(function(key){
    Object.defineProperty(obj,key,{
        get(){
            console.log('get');
        },
        set(val){
            console.log('监听到数据发生了变化',val);
        }
    })
});
obj.name //控制台会打印出 “get”
obj.name = 'xiaohong' //控制台会打印出 "监听到数据发生了变化"

let student={
    num:8888,
    name:"lisi"
}
 student=new Proxy(student,{
   get(){
      console.log("我进来了")
   },
   set(val){
       console.log("proxy",val)
       return val
   }
})
student.name //控制台会打印出 “get”
student.name = 'wangwu' //控制台会打印出 "监听到数据发生了变化"
console 命令行工具 X clear

                    
>
console