简体   繁体   English

如何修复 javascript 代码中的 eslint 错误

[英]How to fix eslint errors in javascript code

    for (const [key, value] of Object.entries(attrs)) {
      element.setAttribute(`${key}`, `${value}`);
    }
  }

I am using this in my code which is used to select the key values of keyboard but some errors are shown by eslint我在我的代码中使用它,它用于 select 键盘的键值,但 eslint 显示了一些错误

error iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations no-restricted-syntax

As @dork correctly pointed out in his comment, ( eslint suggests) you should not use for... of loops.正如@dork 在他的评论中正确指出的那样,( eslint建议)你不应该使用for... of循环。 It is not supported in old browsers and may require a polyfill ( regenerator-runtime ).它在旧浏览器中不受支持,可能需要一个 polyfill ( regenerator-runtime )。

Better write your code this way:最好这样写你的代码:

Object.entries(attrs).forEach(([key, value]) => element.setAttribute(key, value));

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

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