开发者

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

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 ton开发者_如何学Pythons 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?


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

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

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


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*/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜