SOURCE

function sayhi(name){
    console.log("你好啊",name)   
}

// Object.keys(obj).forEach((key)=>{
//     Object.defineProperty(obj,key,{
//         enumerable: true,
//         configurable: true,
//         get(){
            
//             console.log('get')
//         },
//         set(newval){
//             sayhi(newval)
//         }
//     })
// })



function reactive(obj){
    if (typeof obj !== 'object' && obj != null) {
        return obj
    }
    let pxy = new Proxy(obj,{
        set(target,key,value,receiver){
            let res = Reflect.set(target, key,value, receiver)
            console.log(`set${key}:${res}`)
            // console.log(res,'res')
            return res
        },
        get(target, key, receiver){
            let res = Reflect.get(target, key, receiver)
            console.log(`get ${key}:${res}`)
            return res
        }
    })
    return pxy;
}
let obj ={
    name:'a'
}
let pxyofobj = reactive(obj);
pxyofobj.name
// obj.name='bbb'
// pxy.name
console 命令行工具 X clear

                    
>
console