Alex Rivera | Logout

How to rectify "Document was used before it was defined" using Jslint

Asked 2012-05-26T12:27:58.533
27

I get the following error in jsLint:

'document' was used before it was defined.

Line that causes the error:

document.cookie = name + "=" + value + expires + "; path=/";

I get why this happens, but I would like my code to be compliant.

How do I resolve this?

Thanks.

Edit
Report

1 Answer

2

From jslint's website, you can read about a /global/ directive that allows you to set variables that are assumed to be declared elsewhere.

Here is an example (put this at the top of the file):

/\*global var1,var2,var3,var4,var5\*/

or, in starjava's case:

/\*global document\*/

I'm not actually sure if the :true or :false is needed, but it looks like it's recommended from what I read on the site. http://www.jslint.com/lint.html

Make sure the initial global statement is on the same line as '/\*', or else it breaks.

answered 2012-07-18T14:57:53.903

Your Answer