caller

Obsolete
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Summary

Specifies the function that invoked the currently executing function.

Property of arguments
Implemented in JavaScript 1.1
ECMAScript Edition None

Description

This property is not available anymore, but you can still use Function.caller:

 

function whoCalled() {
   if (whoCalled.caller == null)
      console.log('I was called from the global scope.');
   else
      console.log(whoCalled.caller + ' called me!');
}

 

Examples

The following code checks the value of arguments.caller in a function.

function whoCalled() {
   if (arguments.caller == null)
      console.log('I was called from the global scope.');
   else
      console.log(arguments.caller + ' called me!');
}

Document Tags and Contributors

Last updated by: Havvy,