]>
Commit | Line | Data |
---|---|---|
8f9d1d4d DC |
1 | --- |
2 | title: no-caller | |
8f9d1d4d DC |
3 | rule_type: suggestion |
4 | --- | |
5 | ||
eb39fafa DC |
6 | |
7 | The use of `arguments.caller` and `arguments.callee` make several code optimizations impossible. They have been deprecated in future versions of JavaScript and their use is forbidden in ECMAScript 5 while in strict mode. | |
8 | ||
9 | ```js | |
10 | function foo() { | |
11 | var callee = arguments.callee; | |
12 | } | |
13 | ``` | |
14 | ||
15 | ## Rule Details | |
16 | ||
17 | This rule is aimed at discouraging the use of deprecated and sub-optimal code by disallowing the use of `arguments.caller` and `arguments.callee`. As such, it will warn when `arguments.caller` and `arguments.callee` are used. | |
18 | ||
19 | Examples of **incorrect** code for this rule: | |
20 | ||
8f9d1d4d DC |
21 | ::: incorrect |
22 | ||
eb39fafa DC |
23 | ```js |
24 | /*eslint no-caller: "error"*/ | |
25 | ||
26 | function foo(n) { | |
27 | if (n <= 0) { | |
28 | return; | |
29 | } | |
30 | ||
31 | arguments.callee(n - 1); | |
32 | } | |
33 | ||
34 | [1,2,3,4,5].map(function(n) { | |
35 | return !(n > 1) ? 1 : arguments.callee(n - 1) * n; | |
36 | }); | |
37 | ``` | |
38 | ||
8f9d1d4d DC |
39 | ::: |
40 | ||
eb39fafa DC |
41 | Examples of **correct** code for this rule: |
42 | ||
8f9d1d4d DC |
43 | ::: correct |
44 | ||
eb39fafa DC |
45 | ```js |
46 | /*eslint no-caller: "error"*/ | |
47 | ||
48 | function foo(n) { | |
49 | if (n <= 0) { | |
50 | return; | |
51 | } | |
52 | ||
53 | foo(n - 1); | |
54 | } | |
55 | ||
56 | [1,2,3,4,5].map(function factorial(n) { | |
57 | return !(n > 1) ? 1 : factorial(n - 1) * n; | |
58 | }); | |
59 | ``` | |
8f9d1d4d DC |
60 | |
61 | ::: |