Eslint参考手册
规则 | Rules
prefer-rest-params
ES2015中还有其他参数。我们可以使用该特性来代替arguments
可变参数。
arguments
没有Array.prototype
方法,所以这有点不方便。
规则细节
该规则旨在标记arguments
变量的使用。
示例
此规则的错误代码示例:
function foo() {
console.log(arguments);
}
function foo(action) {
var args = Array.prototype.slice.call(arguments, 1);
action.apply(null, args);
}
function foo(action) {
var args = [].slice.call(arguments, 1);
action.apply(null, args);
}
此规则的正确代码示例:
function foo(...args) {
console.log(args);
}
function foo(action, ...args) {
action.apply(null, args); // or `action(...args)`, related to the `prefer-spread` rule.
}
// Note: the implicit arguments can be overwritten.
function foo(arguments) {
console.log(arguments); // This is the first argument.
}
function foo() {
var arguments = 0;
console.log(arguments); // This is a local variable.
}
何时不使用它
此规则不应用于 ES3 / 5环境。
在 ES2015(ES6)或更高版本中,如果您不想收到有关arguments
变量的通知,那么禁用此规则是安全的。
相关规则
- prefer-spread
- Version
- 此规则是在 ESLint 2.0.0-alpha-1.Resources 中引入的
- 规则资源
- 文档资源
规则 | Rules相关

ESLint 是一个代码规范和错误检查工具,有以下几个特性。所有东西都是可以插拔的。你可以调用任意的 rule api 或者 formatter api 去打包或者定义 rule or formatter。任意的 rule 都是独立的。没有特定的 coding style,你可以自己配置。
主页 | https://eslint.org/ |
源码 | https://github.com/eslint/eslint |
发布版本 | 4.12.0 |