[Solved-6 Solutions] Find out caller function in javascript - javascript tutorial
Problem
How to find out the caller function in JavaScript ?
Solution 1:
This code checks the value a function's caller property.
Solution 2:
Just console log your error stack.
Solution 3:
Try this:
Read Also
Call and applySolution 4:
You can use this code:
is equivalent to this:
In case we decide to refactor the name of the invoked function (Hello), we would have to change all its occurrences.
Solution 5:
We can get the full stacktrace:
Until caller is null.
It cause an infinite loop on recursive function.
Solution 6:
We can use Function.Caller to get the calling function. The following code illustrates its use: