简体   繁体   English

如何处理js文件中的未使用变量eslint错误?

[英]How to handle unused variable in js files eslint errors?

I have two different js files one is called alert.js 我有两个不同的js文件,一个叫做alert.js

alert.js alert.js

 function alerts(){ alert('HI'); } 

Another one is called draw.js 另一个叫做draw.js

 function call_alert(){ alerts(); } 
Functionally its working well, but in validation using jslint or eslint shows me these errors: 从功能上来说,它运作良好,但是在使用jslint或eslint进行验证时,向我显示了以下错误:

  • 'alerts' is defined but never used. 定义了“警报”,但从未使用过。 (no-unused-vars) (this error for alert.js file) (无未使用的变量)(alert.js文件的此错误)
  • 'call_alert' is defined but never used. 'call_alert'已定义但从未使用。 (no-unused-vars) (this error for draw.js file) (无未使用的变量)(draw.js文件的此错误)

When you have functions or variables that are defined in the global scope in one file but used in another, you can use exported comments to tell ESLint that they're intended to be used elsewhere. 如果在一个文件中具有在全局范围中定义但在另一个文件中使用的函数或变量,则可以使用导出的注释来告诉ESLint它们打算在其他地方使用。 (Note that this doesn't apply to Node.js or ES modules, which don't have global scope.) (请注意,这不适用于没有全局范围的Node.js或ES模块。)

/* exported alerts */
function alerts() {
    alert('HI');
}

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

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