防止JSHint警告“已定义functionName但从未使用过" [英] Prevent JSHint warning that 'functionName is defined but never used'

查看:222
本文介绍了防止JSHint警告“已定义functionName但从未使用过"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用JSHint(通过Sublime-Linter包用于Sublime Text 2).我想取消有关在定义函数之前使用的函数的警告,因为我认为使用这样的函数定义没有问题.例如,以下代码生成警告:

I have just started using JSHint (through the Sublime-Linter package for Sublime Text 2). I would like to suppress its warnings regarding functions that are used before they are defined, as I see no problem with using function definitions like this. For example, the following code generates warnings:

(function($){ 

    $(document).ready(function()
    {
      formValidationSetup();
      refreshErrorMessages();
    });

    function formValidationSetup()
    {

    }

    function refreshErrorMessages()
    {

    }

})(jQuery);

警告:

  1. formValidationSetup已定义但从未使用
  2. refreshErrorMessages已定义但从未使用

我已经尝试在JSHint选项中将 undef 设置为 false ,但是我仍然遇到这些错误.我应该设置另一个选项吗?形成 undef JSLint文档:

I've tried setting undef to false in the JSHint options, but I'm still getting these errors. Is there another option I should be setting? Form the JSLint docs for undef:

如果在使用前不需要声明变量和函数,则为true.这 在严格模式下不可用.

true if variables and functions need not be declared before used. This is not available in strict mode.

推荐答案

避免警告

已定义但从未使用

defined but never used

在javascript中的jslint中添加注释,例如:

in jslint in your javascript add comments like:

 /*exported formValidationSetup, refreshErrorMessages */

在jshint和jslint中,您可以将未使用的选项设置为false:

In jshint and jslint you can set the unused option to false:

 /*jshint unused:false*/

请参见选项

这篇关于防止JSHint警告“已定义functionName但从未使用过"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆