Caller information in Javascript

Tuesday, 11 November 2008, 7:19 | Category : Javascript
Tags :

Caller – Returns the function that invoked the specified function.

Not a standard javascript function but implemented in Mozilla engine and JScript.

If the function f was invoked by the top level code, the value of f.caller is null, otherwise it’s the function that called f.

Example: Checking the value of a function’s caller property

The following code checks the value a function’s caller property.

function myFunc() {
if (myFunc.caller == null)
return ("The function was called from the top!");
else return ("This function's caller was " + myFunc.caller);