在JS中找到调用函数的函数?

时间:2010-07-16 17:48:41

标签: javascript debugging function

找到调用函数的函数的最佳方法是什么?

例如,如果我有

function first(){
  doSomething();
}

// Lots of code

function doSomething(){
  alert('Somehow, I know that' + ________ + 'function called me...');
  alert('Boink, hit an error, but now you know what function called me');
}

有没有办法获得该调用功能?谢谢!

1 个答案:

答案 0 :(得分:3)

将______替换为doSomething.caller