可能重复:
How do you find out the caller function in JavaScript?
function testA()
{
testAsync(options, testB);
function testB()
{
// some logic
}
}
function testAsync(callback)
{
// Get caller function.
var caller = arguments.callee.caller;
log('log message', caller);
}
从上面的代码中,我需要在testAsync方法中从调用者变量中检索testA函数,这意味着我需要获取当前调用函数的根函数。有可能吗?
谢谢,
答案 0 :(得分:-1)
我不确定这是否有帮助,但我认为你的代码失败了,因为你已经
了 log('log message', caller);
而不是
console.log('log message', caller);