aboutsummaryrefslogtreecommitdiff
path: root/files/pl/web/javascript/reference/global_objects/function/caller/index.html
blob: 1c86b7f92f4844130144d0ad0bae51947107a609 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
title: Function.caller
slug: Web/JavaScript/Referencje/Obiekty/Function/caller
tags:
  - Function
  - JavaScript
  - Non-standard
  - Property
translation_of: Web/JavaScript/Reference/Global_Objects/Function/caller
---
<div>{{JSRef}} {{non-standard_header}}</div>

<h2 id="Podsumowanie" name="Podsumowanie">Podsumowanie</h2>

<p>Określa funkcję, która powołuje się na aktualnie wykonywaną funkcje.</p>

<h2 id="Opis" name="Opis">Opis</h2>

<p>Jeśli funkcja <code>f</code> została wywołana przez kod najwyższego poziomu, własność <code>f.caller</code> ma wartość {{jsxref("null")}}, w przeciwnym przypadku jest to funkcja, która wywołała <code>f</code>.</p>

<p>Ta własność zastąpiła wycofaną własność {{jsxref("arguments.caller")}}.</p>

<h3 id="Notes" name="Notes">Notes</h3>

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

<pre class="brush: js">function f(n) { g(n-1); }
function g(n) { if(n&gt;0) { f(n); } else { stop(); } }
f(2);
</pre>

<p>At the moment <code>stop()</code> is called the call stack will be:</p>

<pre class="eval">f(2) -&gt; g(1) -&gt; f(1) -&gt; g(0) -&gt; stop()
</pre>

<p>The following is true:</p>

<pre class="eval">stop.caller === g &amp;&amp; f.caller === g &amp;&amp; g.caller === f
</pre>

<p>so if you tried to get the stack trace in the <code>stop()</code> function like this:</p>

<pre class="brush: js">var f = stop;
var stack = "Stack trace:";
while (f) {
  stack += "\n" + f.name;
  f = f.caller;
}
</pre>

<p>the loop would never stop.</p>

<h2 id="Przyk.C5.82ady" name="Przyk.C5.82ady">Przykłady</h2>

<h3 id="Przyk.C5.82ad:_Sprawdzenie_warto.C5.9Bci_w.C5.82asno.C5.9Bci_funkcji_caller" name="Przyk.C5.82ad:_Sprawdzenie_warto.C5.9Bci_w.C5.82asno.C5.9Bci_funkcji_caller">Przykład: Sprawdzenie wartości własności funkcji <code>caller</code></h3>

<p>Następujący kod sprawdza wartość własności funkcji <code>caller</code>.</p>

<pre class="brush: js">function myFunc() {
   if (myFunc.caller == null) {
      return ("The function was called from the top!");
   } else {
      return ("This function's caller was " + myFunc.caller);
   }
}
</pre>

<div class="noinclude"> </div>