简体   繁体   English

JsHint警告其他文件中的功能

[英]JsHint warns about functions inside other files

Using Microsoft Visual Studio 2013 Premium 使用Microsoft Visual Studio 2013 Premium

I have a javascript file that contains all of my "extensions", lets call this extensions.js 我有一个包含所有“扩展名”的javascript文件,我们称其为extensions.js

Inside this extensions.js file I have a function. 在这个extensions.js文件中,我有一个函数。 Lets call it RandomFunction. 让我们称之为RandomFunction。

Inside another javascript file (lets call this RandomFile.js) I make use of the RandomFunction file, and inside browsers this is absolutely fine. 在另一个JavaScript文件中(我们称其为RandomFile.js),我使用RandomFunction文件,在浏览器中,这绝对没问题。 However the JsHint is insistent that 但是,JsHint坚持认为

JsHint (W117): 'RandomFunction' is not defined.

Inside of RandomFile.js I have included a 在RandomFile.js内部,我包含了一个

/// <reference path="../extensions/extensions.js" />

as well as adding a global _references.js to the project. 以及向项目添加全局_references.js。

The references seem to work at least as far as my Intellisense is concerned. 这些引用似乎至少对我的Intellisense有用。

Has anyone any idea how to get rid of the warnings without flat out turning them off? 有谁知道如何消除警告而不完全关闭警告?

I'd prefer not to do this as some warnings are genuine. 我不希望这样做,因为某些警告是真实的。

I am using the WebEssenstials addon. 我正在使用WebEssenstials插件。

Regards. 问候。

You can do this on a per-file basis by adding the names of the functions the warnings for which you want suppressed to a global line at the very beginning of each file: 您可以在每个文件的开头,通过在每个文件的开头添加要取消其警告的功能的名称到全局行,来实现此功能:

/* global RandomFunction1, RandomFunction2: true */

Alternatively, if you're using a customised .jshintrc file you can add the function names to the globals object: 或者,如果您使用自定义的.jshintrc文件,则可以将函数名称添加到globals对象:

{
  "globals": {
    "RandomFunction1": true,
    "RandomFunction2": true
  },
  ... rest of the .jshintrc file.
}

There's a lot of information in the JSHint documentation on both global lines and .jshintrc files. .jshintrc 文档中有关全局行和.jshintrc文件的信息很多。

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

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