1 # Suggest using the rest parameters instead of `arguments` (prefer-rest-params)
3 There are rest parameters in ES2015.
4 We can use that feature for variadic functions instead of the `arguments` variable.
6 `arguments` does not have methods of `Array.prototype`, so it's a bit of an inconvenience.
10 This rule is aimed to flag usage of `arguments` variables.
14 Examples of **incorrect** code for this rule:
18 console.log(arguments);
21 function foo(action) {
22 var args = Array.prototype.slice.call(arguments, 1);
23 action.apply(null, args);
26 function foo(action) {
27 var args = [].slice.call(arguments, 1);
28 action.apply(null, args);
32 Examples of **correct** code for this rule:
35 function foo(...args) {
39 function foo(action, ...args) {
40 action.apply(null, args); // or `action(...args)`, related to the `prefer-spread` rule.
43 // Note: the implicit arguments can be overwritten.
44 function foo(arguments) {
45 console.log(arguments); // This is the first argument.
49 console.log(arguments); // This is a local variable.
55 This rule should not be used in ES3/5 environments.
57 In ES2015 (ES6) or later, if you don't want to be notified about `arguments` variables, then it's safe to disable this rule.
61 * [prefer-spread](prefer-spread.md)