Jquery and Jslint - '$' was used before it was defined

孤街醉人 提交于 2019-12-17 10:44:23

问题


I have some third party javascript im working with, I added some jquery code into it the javascript file. But it seems to fail on the above code when validating using Jslint

'$' was used before it was defined.

I can see at the top of the javascript file it states:

/*global alert: false, console: false, jQuery: false */

Im relatively new to Javascript, and JQuery, so any help would be welcome.


回答1:


Add these options to your comments:

/*jslint browser: true*/
/*global $, jQuery, alert*/



回答2:


If you want to use variables provided by other scripts, then you need to say so:

/*global $ */



回答3:


For JSLint In Netbeans IDE go to:

Tools - Options - Miscellaneous - JSLint tab - Text area under "Predefined (, separated)":

  • add $;
  • add your other project global variables, separating with comma.

Now JQuery variable $ is considered defined everywhere in code.



来源:https://stackoverflow.com/questions/18251388/jquery-and-jslint-was-used-before-it-was-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!