function caller

Description

caller is a reference to the function that called this function or null if the function was called from the global scope.

Example


function outer(){
   inner();
}
function inner(){
   console.log(inner.caller);
}
outer();

Because outer() calls inner(), inner.caller points back to outer().

Example 2

You can even call arguments.callee.caller:


function outer(){/*w  w  w .ja  va 2  s  . c  o  m*/
   inner();
}

function inner(){
   console.log(arguments.callee.caller);
}
outer();

The code above generates the following result.

Note

In strict mode, arguments.callee and arguments.caller are not supported.





















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions