我无法解决这个问题,请帮助我。
const params =
arguments.length > 3 && arguments[3] !== undefined
? arguments[3]
: null;
问题出在参数上[3] ESLint 说:使用其余参数而不是“参数”。 (首选休息参数)
最佳答案
我不知道你的函数在发生这种情况时是什么样子,但我会给你一个 ESLint 正在谈论的 rest params
示例以及你提供的一小段代码:
function foo( ...args ) {
console.log( args );
const params =
args.length > 3 && args[3] !== undefined
? args[3]
: null;
console.log( params );
}
foo( 1, 2, 3, 4 );
所以 ...args
是在函数调用中传递的所有参数的数组,但您尚未将其设置为参数。您拥有的任何参数都位于 ...args
前面。 (请注意,您可以将其称为任何您想要的名称,例如...rest
。)这可能比参数更受青睐的原因是您无法在它,而在其余参数上你可以。
关于javascript - 定义常量时出现错误 ESLint : Use the rest parameters instead of 'arguments' . (prefer-rest-params),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56570085/