赞
踩
1,首先要说的肯定是 Proxy 了,直接上代码:
- 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("_key ",_key)
- }
- 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.location = {a: 2};
- window.location.a;
- window.b = {a: 2};
- window.b.a;
- location.port;
- console.log("--------------");
- window.location.port;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。