1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
ld = {}; ld.config = {}; ld.config.proxy = true;
ld.getType = function getType(obj){ return Object.prototype.toString.call(obj); }
ld.proxy = function proxy(obj, objName){ if(!ld.config.proxy){ return obj; } let handler = { get:function (target,prop,receiver){ let result; try { result = Reflect.get(target,prop,receiver); let type = ld.getType(result); if(result instanceof Object){ console.log(`{get|obj:[${objName}] -> prop:[${prop.toString()}],type:[${type}]}`); result = ld.proxy(result, `${objName}.${prop.toString()}`); }else if(typeof result === "symbol"){ console.log(`{get|obj:[${objName}] -> prop:[${prop.toString()}],ret:[${result.toString()}]}`); }else{ console.log(`{get|obj:[${objName}] -> prop:[${prop.toString()}],ret:[${result}]}`); }
}catch (e) { console.log(`{get|obj:[${objName}] -> prop:[${prop.toString()}],error:[${e.message}]}`); } return result; }, set:function (target,prop,value,receiver){ let result; try{ result = Reflect.set(target,prop,value,receiver); let type = ld.getType(value); if(value instanceof Object){ console.log(`{set|obj:[${objName}] -> prop:[${prop.toString()}],type:[${type}]}`); }else if(typeof value === "symbol"){ console.log(`{set|obj:[${objName}] -> prop:[${prop.toString()}],value:[${value.toString()}]}`); }else{ console.log(`{set|obj:[${objName}] -> prop:[${prop.toString()}],value:[${value}]}`); } }catch (e){ console.log(`{set|obj:[${objName}] -> prop:[${prop.toString()}],error:[${e.message}]}`); } return result; }, getOwnPropertyDescriptor:function (target, prop){ let result; try{ result = Reflect.getOwnPropertyDescriptor(target, prop); let type = ld.getType(result); console.log(`{getOwnPropertyDescriptor|obj:[${objName}] -> prop:[${prop.toString()}],type:[${type}]}`); }catch (e){ console.log(`{getOwnPropertyDescriptor|obj:[${objName}] -> prop:[${prop.toString()}],error:[${e.message}]}`); } return result; }, defineProperty: function (target, prop, descriptor){ let result; try{ result = Reflect.defineProperty(target, prop, descriptor); console.log(`{defineProperty|obj:[${objName}] -> prop:[${prop.toString()}]}`); }catch (e) { console.log(`{defineProperty|obj:[${objName}] -> prop:[${prop.toString()}],error:[${e.message}]}`); } return result; }, apply:function (target, thisArg, argumentsList){ let result; try{ result = Reflect.apply(target, thisArg, argumentsList); let type = ld.getType(result); if(result instanceof Object){ console.log(`{apply|function:[${objName}], type:[${type}]}`); }else if(typeof result === "symbol"){ console.log(`{apply|function:[${objName}], result:[${result.toString()}]}`); }else{ console.log(`{apply|function:[${objName}], result:[${result}]}`); } }catch (e) { console.log(`{apply|function:[${objName}],error:[${e.message}]}`); } return result; }, construct:function (target, argArray, newTarget) { let result; try{ result = Reflect.construct(target, argArray, newTarget); let type = ld.getType(result); console.log(`{construct|function:[${objName}], type:[${type}]}`); }catch (e) { console.log(`{construct|function:[${objName}],error:[${e.message}]}`); } return result;
}, deleteProperty:function (target, propKey){ let result = Reflect.deleteProperty(target, propKey); console.log(`{deleteProperty|obj:[${objName}] -> prop:[${propKey.toString()}], result:[${result}]}`); return result; }, has:function (target, propKey){ let result = Reflect.has(target, propKey); console.log(`{has|obj:[${objName}] -> prop:[${propKey.toString()}], result:[${result}]}`); return result; }, ownKeys: function (target){ let result = Reflect.ownKeys(target); console.log(`{ownKeys|obj:[${objName}]}`); return result }, getPrototypeOf:function(target){ let result = Reflect.getPrototypeOf(target); console.log(`{getPrototypeOf|obj:[${objName}]}`); return result; }, setPrototypeOf:function(target, proto){ let result = Reflect.setPrototypeOf(target, proto); console.log(`{setPrototypeOf|obj:[${objName}]}`); return result; }, preventExtensions:function(target){ let result = Reflect.preventExtensions(target, proto); console.log(`{preventExtensions|obj:[${objName}]}`); return result; }, isExtensible:function(target){ let result = Reflect.isExtensible(target, proto); console.log(`{isExtensible|obj:[${objName}]}`); return result; } }; return new Proxy(obj, handler); }
|