簡體   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