javascriptdebuggingfunction

Find the function calling the function in JS?


What's the best way to find the function that's calling the function?

For example, if I have

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');
}

Is there any way to get that calling function? Thanks!


Solution

  • Replace ______ with doSomething.caller.