我希望函数在运行时能够控制console.log()的名称。通过这种方式,我可以分辨出我正在吃的这一大块意大利面条代码中正在运行哪些功能。
到目前为止,我已经有了这个
function printGlobalFunctions() {
var PRINT_FUNCTION_NAME = "\
var identify_name = arguments.callee;\
var identify_regEx = new RegExp('.*?(?=\\\\()');\
identify_name = identify_regEx.exec(identify_name);\
identify_name = identify_name.toString();\
identify_name = identify_name.replace('function ', '');\
console.log(identify_name);"; //.*?(?=\()
for (var prop in window) {
if (typeof window[prop] === "function") {
var func = window[prop].toString();
if (/\[native code\]/.test(func) === false) {
if (/\$/.test(prop) !== true && /jQuery/.test(prop) !== true) {
func = func.replace(PRINT_FUNCTION_NAME, "");
func = func.replace(/{/, "{" + PRINT_FUNCTION_NAME);
eval(prop + "=" + func);
}
}
}
}
}
但只打印全局函数。我想它也可以打印成员函数和匿名函数。我想你会修改Function.prototype
,但我不知道。覆盖Function.Prototype.Call
是不够的,因为只有.01%的函数使用myFunc.call()调用