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:
17 /*eslint prefer-rest-params: "error"*/
20 console.log(arguments);
23 function foo(action) {
24 var args = Array.prototype.slice.call(arguments, 1);
25 action.apply(null, args);
28 function foo(action) {
29 var args = [].slice.call(arguments, 1);
30 action.apply(null, args);
34 Examples of **correct** code for this rule:
37 /*eslint prefer-rest-params: "error"*/
39 function foo(...args) {
43 function foo(action, ...args) {
44 action.apply(null, args); // or `action(...args)`, related to the `prefer-spread` rule.
47 // Note: the implicit arguments can be overwritten.
48 function foo(arguments) {
49 console.log(arguments); // This is the first argument.
53 console.log(arguments); // This is a local variable.
59 This rule should not be used in ES3/5 environments.
61 In ES2015 (ES6) or later, if you don't want to be notified about `arguments` variables, then it's safe to disable this rule.
65 * [prefer-spread](prefer-spread.md)