开发者

JSLint warns that "document" is not fully defined on jQuery(document).ready

I get a

'document' has not been fully defined yet.
    $(document).ready(function () {

warning from jsLint. I get why this happends but I would like my code to be warning free.

My question is - how do I either solve this in code (assign document to itself? var document=docu开发者_如何学Pythonment?) or maybe make the warning go away some other way.

Thanks.


You can simply use

/*jslint browser:true */

in the beginning of the code to assume a browser.


I think you can safely ignore that. If you don't want it to show anyway, rewrite it like so

$(function () {
    // Document is ready
});

$(function () {}) and $(document).ready(function () {}) are equivalent.


Use the shorthand:

$(function() {
   ...
});


If you prefer to keep your code the way you have it, you can tell JSlint to be OK with your decision:

/*global document*/
$(document).ready(function () {
    ...
}

This indicates that document has been defined elsewhere.


JSLint requires that you assume a browser in the selector options. the document will be defined then. Using $ will not help here...not in JSLint anyway.


create an .jsintrc on root folder, with this:

{ "browser": true }

You can see all options in JSHint Options

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜