Is there a way to return the function that invoked the current function? Function.caller will only work for non-strict mode applications.
I want to be able to use this functionality for production environment, therefore I need strict mode to be turned on.
Expected return: function itself or the name of function.
function a() {
b()
}
function b() {
console.log(b.caller)
}
Function.caller will throw an error when used in strict mode:
Uncaught TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them
One possible way is use Console.trace
function a() {
b()
}
function b() {
console.trace()
}
a()
Check the browser console to see output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With