This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

La propietat function.caller retorna la funci贸 que ha invocat la funci贸 especificada.


SI la funci贸 f ha estat invocada pel codi de nivell superior, el valor de f.caller 茅s null, sin贸 茅s la funci贸 que ha cridat f.

Aquesta propietat reempla莽a la propietat obsoleta arguments.caller de l'objecte arguments.

La propietat especial __caller__, la qual retorna l'objecte activatwhich returned the activation object of the caller thus allowing to reconstruct the stack, was removed for security reasons.


Vegeu que en cas de recursi贸, no podeu reconstruir la pila de crida fent servir aquesta propietat. C that in case of recursion, you can't reconstruct the call stack using this property. Tingueu en compte:

function f(n) { g(n - 1); }
function g(n) { if (n > 0) { f(n); } else { stop(); } }

At the moment stop() is called the call stack will be:

f(2) -> g(1) -> f(1) -> g(0) -> stop()

El seg眉ent 茅s cert:

stop.caller === g && f.caller === g && g.caller === f

so if you tried to get the stack trace in the stop() function like this:

var f = stop;
var stack = 'Stack trace:';
while (f) {
  stack += '\n' +;
  f = f.caller;

El bucle mai s'aturaria.


Checking the value of a function's caller property

El codi seg眉ent comprova que el valor 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;


No forma part de cap especificaci贸. Implementat en JavaScript 1.5.

Compatibilitat amb navegadors

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help! (en-US)
Caracter铆stica Chrome Firefox (Gecko) Internet Explorer Opera Safari
Suport b脿sic (Yes) 1.0 (1.7 or earlier) 8.0 (Yes) (Yes)
Caracter铆stica Android Chrome per Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Suport b脿sic (Yes) (Yes) 1.0 (1.0) (Yes) (Yes) (Yes)

Vegeu tamb茅