aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/javascript/reference/functions/arguments/callee/index.html
blob: eaf41af79df653c3beb5406f5689248933bfa2ff (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
---
title: arguments.callee
slug: Web/JavaScript/Reference/Functions/arguments/callee
translation_of: Web/JavaScript/Reference/Functions/arguments/callee
---
<div>{{jsSidebar("Functions")}}</div>

<p>Свойство <code><strong>callee</strong> псевдомассива <strong>arguments</strong></code> хранит ссылку на функцию-родитель.</p>

<h2 id="Описание">Описание</h2>

<div class="warning"><strong>Внимание:</strong> В ES5 <a href="/en-US/docs/JavaScript/Reference/Functions_and_function_scope/Strict_mode" title="/en-US/docs/JavaScript/Reference/Functions_and_function_scope/Strict_mode">strict mode</a> использование <code>arguments.callee</code> запрещено.</div>

<h3 id="Зачем_вообще_использовать_arguments.callee">Зачем вообще использовать <code>arguments.callee</code>?</h3>

<p>В ранних версиях javaScript отсутствовала такая фишка, как <a href="https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/function#%D0%98%D0%BC%D0%B5%D0%BD%D0%BE%D0%B2%D0%B0%D0%BD%D0%BD%D0%BE%D0%B5_%D1%84%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D0%BE%D0%BD%D0%B0%D0%BB%D1%8C%D0%BD%D0%BE%D0%B5_%D0%B2%D1%8B%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5">Named Function Expression </a>и единственным спасением было свойство <strong>callee</strong>. К примеру:</p>

<pre class="brush: js">var f = function test() {
    alert(typeof test); //undefined
    alert(typeof arguments.callee); //function
}
</pre>

<p>В нынешние времена, когда мы уже можем работать с <em>NFE</em>, надобность в использовании свойства <strong>callee </strong>сама собой отпадает<strong>.</strong></p>

<pre class="brush: js">var f = function test(){
   alert(typeof test); //function
}</pre>

<p> </p>

<p>Действительно незаменимым оно остается всего в одной ситуации. Когда мы создаем анонимную функцию напрямую через конструктор <em>Function.</em></p>

<pre class="line-numbers  language-javascript"><code class="language-javascript"><span class="keyword token">var b = new Function("", "alert(typeof arguments.callee)");</span></code></pre>

<p> </p>

<h2 id="Пример_использования">Пример использования</h2>

<p> </p>

<h3 id="Использование_arguments.callee_для_создания_рекурсии">Использование <code>arguments.callee</code> для создания рекурсии</h3>

<pre class="line-numbers  language-javascript"><code class="language-javascript"><span class="keyword token">var factorial = function</span><span class="punctuation token">(</span>n<span class="punctuation token">)</span> <span class="punctuation token">{</span>
  <span class="keyword token">return</span> n<span class="operator token"> == </span><span class="number token">1</span> <span class="operator token">?</span> <span class="number token">1</span> <span class="punctuation token">:</span> n<span class="operator token"> * </span>arguments<span class="punctuation token">.</span><span class="function token">callee</span><span class="punctuation token">(</span>n<span class="number token">-1</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
<span class="punctuation token">};

</span><span class="keyword token">factorial</span></code>(7);
</pre>

<p> </p>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES1')}}</td>
   <td>{{Spec2('ES1')}}</td>
   <td>Initial definition. Implemented in JavaScript 1.2</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-10.6', 'Arguments Object')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-arguments-exotic-objects', 'Arguments Exotic Objects')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-arguments-exotic-objects', 'Arguments Exotic Objects')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{jsxref("Function")}}</li>
</ul>