SOURCE

// https://zhuanlan.zhihu.com/p/394997671 

const obj = {
    a: 1,
    b: 2,
    c: {
        c1: 3,
        c2: 4
    }
}

const nObj = new Proxy(obj, {
    // 对 in 拦截
    has: function (target, prop) {
        var res = Reflect.has(target, prop);
        console.log('Proxy.has', prop, target === obj);
        return res;
    },
    // 对 读取属性 拦截
    get: function (target, prop) {
        var res = Reflect.get(target, prop);
        // if (['c'].includes(prop)) {
        //     return;
        // }
        console.log('Proxy.get', target, prop);
        return res;

    },
    // 对 设置属性 拦截
    set: function (target, prop, value) {
        var res = Reflect.set(target, prop, value);
        console.log('Proxy.set', target, prop, value);
        return res;
    },
    // 对 删除属性 拦截
    deleteProperty: function (target, prop) {
        var res = Reflect.deleteProperty(target, prop);
        console.log('Proxy.delete', target, prop);
        return res;
    }
})

// 'a' in nObj;                // Proxy.has a true
// Reflect.has(nObj, 'a');     // Proxy.has a true
// with (nObj) {
//     (a);                    // // Proxy.has a true
// }

// console.log(nObj.a);
// nObj.b = 'b';
// delete nObj.c;
// console.log(nObj);

// 访问隔离
console.log(nObj)




console 命令行工具 X clear

                    
>
console