Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I worry about "window is not defined" JSLint strict mode error?

This won't pass JSLint in strict mode:

"use strict";
(function (w) {
   w.alert(w);
}(window));

The error--from jslint.com--looks like this:

Problem at line 4 character 3: 'window' is not defined.

}(window));

Implied global: window 4

Do I need to tell JSLint to ignore the error, or am I seriously doing something wrong?

like image 778
Kent Brewster Avatar asked Dec 05 '09 21:12

Kent Brewster


2 Answers

Try adding the following:

/*jslint browser: true */
/*global window */

(or check Assume a browser checkbox).

The first line adds general browser support. The second line declares window to be a global variable.

From the documentation:

The browser option does not include the aliases of the global object, window and self.

like image 128
MBO Avatar answered Sep 20 '22 15:09

MBO


Got it, after a false start. I first tried this:

/* global window */

... which didn't work. This did:

/*global window */

The space after the initial asterisk turns out to be important.

like image 23
Kent Brewster Avatar answered Sep 18 '22 15:09

Kent Brewster