简体   繁体   English

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

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

I can't resolve this, please help me. 我无法解决此问题,请帮助我。

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

The problem is with arguments[3] ESLint says: Use the rest parameters instead of 'arguments'. 问题在于参数[3],ESLint说:使用其余参数代替“参数”。 (prefer-rest-params) (喜欢休息-PARAMS)

I don't know what your function looks like where this is happening, but I'll give you an example of the rest params ESLint is talking about with the tiny snippet of code you provided: 我不知道您的函数在哪里发生,但是我会给您一个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 ); 

So ...args is an array of all arguments passed on in the function call that you have not set as a parameter. 因此...args是在函数调用中传递的所有尚未设置为参数的参数的数组。 Any parameter you do have, goes in front of ...args . 您拥有的任何参数都在...args前面。 (Note that you can call this anything you want, such as ...rest .) The reason this might be preferred over arguments is because you cannot use any Array methods on it, while on the rest params you can. (请注意,您可以将其命名为任何名称,例如...rest 。)之所以优先使用此参数,是因为您不能在其上使用任何Array方法,而可以在其余参数上使用。

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

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