1

I am trying to get the name of a function which called the current function in jquery.

For example, say there are three functions

function a, function b, function c

and when one of those functions call function z, i would like to be able to get a string output of the function that called function z if that is possible please?

Brian Tyndall
  • 186
  • 3
  • 12

2 Answers2

3

Javascript provides a mechanism for accessing the current function's callee:

function FunctionA() {
    alert(arguments.callee.caller.name);
}

function FunctionB() {
    FunctionA();
}

FunctionB();

The following JSFiddle demonstrates this, too. http://jsfiddle.net/8UFe2/

thesheps
  • 635
  • 4
  • 11
1

you would use arguments.callee to get the calling function

DiverseAndRemote.com
  • 19,314
  • 10
  • 61
  • 70