# Function.caller

Naši dobrovolníci ještě tento článek do jazyka Čeština nepřeložili. Přidejte se a pomozte nám tuto práci dokončit!
Tento článek si můžete přečíst také v jazyce English (US).

Non-standard
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.

The `function.caller` property returns the function that invoked the specified function. This property is forbidden in strict mode.

## Description

If the function `f` was invoked by the top level code, the value of `f.caller` is `null`, otherwise it's the function that called `f`.

This property replaces the obsolete `arguments.caller` property of the `arguments` object.

The special property `__caller__`, which returned the activation object of the caller thus allowing to reconstruct the stack, was removed for security reasons.

### Notes

Note that in case of recursion, you can't reconstruct the call stack using this property. Consider:

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

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

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

The following is true:

```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.name;
f = f.caller;
}
```

the loop would never stop.

## Examples

### Checking the value of a function's `caller` property

The 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;
}
}
```

## Specifications

Not part of any specification. Implemented in JavaScript 1.5.

## Browser compatibility

Update compatibility data on GitHub
Desktop Mobile Server Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Chrome Full support Yes Edge Full support 12 Firefox Full support 1 IE Full support 8 Opera Full support Yes Safari Full support Yes WebView Android Full support Yes Chrome Android Full support Yes Firefox Android Full support 4 Opera Android Full support Yes Safari iOS Full support Yes Samsung Internet Android Full support Yes nodejs Full support Yes

### Legend

Full support
Full support
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.