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

我只是一个虾纸丫 提交于 2019-12-04 16:28:09

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1853473/should-i-worry-about-window-is-not-defined-jslint-strict-mode-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!