未定义JSLint ES6窗口

时间:2018-08-24 12:24:57

标签: javascript jslint

我正在使用最新的JSLint,并且让JSLint抱怨该窗口未定义。使用es6 JSLint指令时,不允许使用全局变量。

/*jslint es6*/
import AppConst from "@/constants/app.constant.js";
const applicationConfig = {
    showMobileView: null,
    is_iphone: null,
    imageryViewUseSubnav: null
};
window.addEventListener("resize", function () {
    applicationConfig.showMobileView = utilityService.is_small_device();
    applicationConfig.imageryViewUseSubnav = 
    utilityService.is_small_device();
    applicationConfig.is_iphone = utilityService.is_iphone();
});
export default applicationConfig;

1 个答案:

答案 0 :(得分:0)

您必须告诉JSLint您在浏览器环境中。

您还有其他一些错误-未导入的utilityService,导出的对象中没有Object.freeze,等等。

如果我将它们全部清理干净,则会得到下面的内容,该内容在今天的JSLint.com上没有任何其他更改,就不显眼:

/*jslint browser */

// this wasn't used: import AppConst from "@/constants/app.constant.js";
import utilityService from "@/somewhere/file.js";

const applicationConfig = {
    showMobileView: null,
    is_iphone: null,
    imageryViewUseSubnav: null
};
window.addEventListener("resize", function () {
    applicationConfig.showMobileView = utilityService.is_small_device();
    applicationConfig.imageryViewUseSubnav =
            utilityService.is_small_device();
    applicationConfig.is_iphone = utilityService.is_iphone();
});
export default Object.freeze(applicationConfig);