Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

jslint

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.

like image 966
starjava Avatar asked May 26 '12 12:05

starjava


1 Answers

Place

/*jslint browser:true */ 

in the beginning of the body of your function. Or, alternatively, you may use

/*global document: false */ 

JSLint is for the checking of any javascript code, and the document global object does not exists everywhere, so you have to manually tell JSLint that your code is aimed to be executed in browser, and thus document global variable is defined. For example, for server-side javascript it is expected for JSLint to report about this error.

like image 181
penartur Avatar answered Sep 16 '22 15:09

penartur