繁体   English   中英

定义带有错误ESLint的const:使用rest参数代替“ arguments”。 (喜欢休息-PARAMS)

[英]Defining a const with error ESLint: Use the rest parameters instead of 'arguments'. (prefer-rest-params)

我无法解决此问题,请帮助我。

 const params =
        arguments.length > 3 && arguments[3] !== undefined
          ? arguments[3]
          : null;

问题在于参数[3],ESLint说:使用其余参数代替“参数”。 (喜欢休息-PARAMS)

我不知道您的函数在哪里发生,但是我会给您一个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 。)之所以优先使用此参数,是因为您不能在其上使用任何Array方法,而可以在其余参数上使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM