function main()
{
Hello();
}
function Hello()
{
// How do you find out the caller function is \'main\'?
}
Is there a way to find out the call
In both ES6 and Strict mode, use the following to get the Caller function
console.log((new Error()).stack.split("\n")[2].trim().split(" ")[1])
Please note that, the above line will throw an exception, if there is no caller or no previous stack. Use accordingly.
To get callee (the current function name), use:
console.log((new Error()).stack.split("\n")[1].trim().split(" ")[1])