2
在JavaScript中,我可以使用foo.caller来获取堆栈跟踪中foo上方函数的引用。但是,当函数在同一个堆栈跟踪中出现多次时,这不起作用,foo.caller只是返回foo。在递归代码中使用Javascript function.caller的堆栈跟踪?
是否存在稳定的跨平台方法在Javascript中获取完整堆栈跟踪?我不要想要得到一个可打印的堆栈跟踪;相反,我正在进行堆栈检查,以查看某个方法是否位于堆栈中的任何位置。这是我现在的代码:
function inFunction(foo) {
var caller = inFunction.caller;
var maxDepth = 20;
while(caller && --maxDepth > 0) {
if(caller == foo)
return true;
caller = caller.caller;
}
return false;
}
任何想法如何处理堆栈跟踪中存在多次函数?
您是否检出http://stackoverflow.com/questions/103598/why-was-the-arguments-callee-caller-property-deprecated-in-javascript/235760#235760 – ken 2011-03-21 21:29:59
快速参考:https: //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller – oneamongu 2014-01-21 17:18:37