Export (0) Print
Expand All

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 running in fast mode, the default for JScript .NET. To compile a program from the command line that uses the caller property, 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();

After compiling this program with the /fast- option, the output of this program is:

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

Requirements

Version 2

See Also

function Statement

Applies To: arguments Object | Function object

Show:
© 2014 Microsoft