function main()
{
Hello();
}
function Hello()
{
// How do you find out the caller function is 'main'?
}
Is there a way to find out the call stack at all?
function main()
{
Hello();
}
function Hello()
{
// How do you find out the caller function is 'main'?
}
Is there a way to find out the call stack at all?
Just console log your error stack. You can then know how are you being called
Why all of the solutions above look like a rocket science. Meanwhile, it should not be more complicated than this snippet. All credits to this guy
How do you find out the caller function in JavaScript?
It's safer to use
*arguments.callee.caller
sincearguments.caller
is deprecated...You can use Function.Caller to get the calling function. The old method using argument.caller is considered obsolete.
The following code illustrates its use:
Notes about obsolete argument.caller: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/caller
Be aware Function.caller is non-standard: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller