How can I use JSLint for a segment of code which depends on JQuery?

别来无恙 提交于 2019-12-12 14:24:49

问题


I'm relatively new to Javascript, and I'd like to run the piece of code I spent the weekend playing with through JSLint so that it can point out where I was being a total idiot :)

Unfortunately, I get tons of errors about missing function declarations, which are part of the JQuery javascript library and various plugins for it.

Is there any way I can run such code through JSLint?


回答1:


If you're using the web version of jslint, you can simply add the $ object in the predefined option:

If you're using a local copy of jslint, you'd want to set the predef option to $ in the options object.




回答2:


In addition to Daniel's answer, you can "declare" $ on a per-file basis by including the following comment:

/*global $*/

(Note: no space is allowed between /* and global.)

For web stuff you'll often also want to include window, i.e.

/*global $, window*/


来源:https://stackoverflow.com/questions/3920012/how-can-i-use-jslint-for-a-segment-of-code-which-depends-on-jquery

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