admin管理员组

文章数量:1415467

I just tested my custom gallery script at JSLint.. and all errors where solved except for one. The implied global error.. Is this really an error? Can I ignore it or should I work on it to solve this error..?

Thank you for your responses!

Error:
Implied global:
<bunch of vars and other stuff i dont know>

What does this mean? BTW I use JQuery Library.. maybe thats the problem^^..

I just tested my custom gallery script at JSLint.. and all errors where solved except for one. The implied global error.. Is this really an error? Can I ignore it or should I work on it to solve this error..?

Thank you for your responses!

Error:
Implied global:
<bunch of vars and other stuff i dont know>

What does this mean? BTW I use JQuery Library.. maybe thats the problem^^..

Share Improve this question asked Jan 7, 2011 at 11:58 TomkayTomkay 5,16021 gold badges65 silver badges94 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 6

if you use externally declared variables like in this case, put a 'global' statement at the top of your file, like this:

/*global $, document */

JSLint documentation says:

Undefined Variables and Functions

JavaScript's biggest problem is its dependence on global variables, particularly implied global variables. If a variable is not explicitly declared (usually with the var statement), then JavaScript assumes that the variable was global. This can mask misspelled names and other problems.

JSLint expects that all variables and functions are declared before they are used or invoked. This allows it to detect implied global variables. It is also good practice because it makes programs easier to read.

Care for that error. Nearly every coding convention wants you not to use implied globals.

Variables can be declared using the var keyword.

When writing JavaScript code for a browser, it is useful to indicate to JSLint that you are in browser mode, such as by including this:

/*jslint browser: true */

This should resolve 'document', 'setTimeout', and other typical browser defaults

Since jQuery is probably not being evaluated in the same context as your JavaScript, you'll need to let it be known that the ever-useful '$' is available with:

/*global $ */

本文标签: jqueryJSLint (Javascript Validator Website)Error Implied global Stack Overflow