window.luan_text = ""; window.luan_open = false; function luan_proxy(arr, name) { // arr 内存 // name 名字 // 获取数据类型 function get_value_type(value) { // 'undefined', 'null', 'boolean', 'string', 'number', 'symbol', 'array', 'object', 'function' if (Array.isArray(value)) { return "array"; } if (value == null) { return "null"; } return typeof value; } // 打印函数 function luan_print(obj) { let type = get_value_type(obj); if (["undefined", "null", "boolean", "string", "number"].includes(type)) { return obj; } else if (obj[Symbol.toStringTag]) { return obj[Symbol.toStringTag]; } else if (type == "function") { return `function ${obj.name}`; } else if (type == "object" || type == "array") { // JSON.stringify 会递归处理 let temp = JSON.stringify(obj, function (k, v) { if (v && v[Symbol.toStringTag]) { return v[Symbol.toStringTag]; } else if (v && typeof v == "function") { return `function ${v.name}`; } else { return v; } }); return temp; } else if (type == "symbol") { return obj.toString(); } else { // 未预料到的情况 debugger; } } // 句柄 let handle = { get(target, property, receiver) { let result; result = Reflect.get(target, property, receiver); try { if (window.luan_open) { let content = luan_print(target); window.luan_text += `${name}|get| 下标: ${property.toString()} 内容: ${content}\r\n`; } } catch (e) { debugger; } return result; }, set(target, property, value, receiver) { let result; result = Reflect.set(target, property, value, receiver); try { if (window.luan_open) { let content = luan_print(target); window.luan_text += `${name}|set| 下标: ${property.toString()} 内容: ${content}\r\n`; } } catch (e) { debugger; } return result; }, }; return new Proxy(arr, handle); } //……………… p = luan_proxy(p, "p1");
标签:function,return,收集,type,value,proxy,obj,luan From: https://www.cnblogs.com/angdh/p/18258425