浏览器环境监控

2020-08-18  本文已影响0人  周周周__
window = new Proxy(global,{
    get: function(target, key, receiver) {
        console.log("window.get", key, target[key]);
        if (key == "location") {
            location = new Proxy(target[key],{
                get: function(_target, _key, _receiver) {
                    console.log("window.get", key, _key, _target[_key]);
                    if (_key == "port") {
                        console.log("111")
                    }
                    return _target[_key];
                }
            })
        }
        return target[key];
    },
    set: function(target, key, value, receiver) {
        console.log("window.set", key, value);
        target[key] = value;
    }
});



window.a = {}
window.a;
window.b = {a:2};
window.b.a;

输出:

window.set a {}
window.get a {}
window.set b { a: 2 }
window.get b { a: 2 }
上一篇下一篇

猜你喜欢

热点阅读