美文网首页
浏览器环境监控

浏览器环境监控

作者: 周周周__ | 来源:发表于2020-08-18 20:09 被阅读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 }
    

    相关文章

      网友评论

          本文标题:浏览器环境监控

          本文链接:https://www.haomeiwen.com/subject/hgokjktx.html