Share via


caller Property

Returns a reference to the function that invoked the current function.

function.caller 

Arguments

  • function
    Required. The name of the currently executing Function object.

Remarks

The caller property is only defined for a function while that function is executing. If the function is called from the top level of a JScript program, caller contains null.

If the caller property is used in a string context, the result is the same as functionName.toString, that is, the decompiled text of the function is displayed.

Note

The caller property is not available when a program is running in fast mode, the default for JScript. To compile a program that uses the caller property from a command prompt, you must turn off the fast option by using /fast-. It is not safe to turn off the fast option in ASP.NET because of threading issues.

Example

The following example illustrates the use of the caller property.

function callLevel()
{
    if (callLevel.caller == null)
        print("callLevel was called from the top level.");
    else
    {
        print("callLevel was called by:");
        print(callLevel.caller);
    }
}

function testCall()
{
    callLevel()
}

// Call callLevel directly.
callLevel();
// Call callLevel indirectly.
testCall();

The output of this program is as follows.

callLevel was called from the top level.
callLevel was called by:
function testCall() {
   callLevel()
}

Requirements

Version 2

Applies To:

arguments Object| Function Object

See Also

Reference

function Statement

Change History

Date

History

Reason

July 2009

Modified example.

Content bug fix.

July 2009

Modified note about the /fast option.

Content bug fix.

March 2009

Modified example and information about /fast option.

Content bug fix.