繁体   English   中英

.js文件的ESLint错误

[英]ESLint errors with .js file

更新我删除了env代码,我仍然接受我的代码6个ESLint错误,我不知道为什么。

错误如下:

错误:未定义“窗口”。 [no-undef] if($(window).width()<= 640){

错误:已定义“ initMap”,但从未使用过。 [no-unused-vars]函数initMap(){

错误:未定义“ google”。 [no-undef] var map = new google.maps.Map(document.getElementById(“ map”),{

错误:未定义“文档”。 [no-undef] var map = new google.maps.Map(document.getElementById(“ map”),{

错误:“标记”已分配一个值,但从未使用。 [no-unused-vars] var marker = new google.maps.Marker({

错误:未定义“ google”。 [no-undef] var marker = new google.maps.Marker({

任何帮助,将不胜感激!

/*eslint-env jquery*/

if ($(window).width() <= 640) {
$(".cross").hide();
$(".menu").hide();
$(".hamburger").show();

$(".hamburger").on("click", function () {
    $(".menu").slideToggle("slow");
    $(".hamburger").hide();
    $(".cross").show();
});

$(".cross").on("click", function () {
    $(".menu").slideToggle("slow");
    $(".cross").hide();
    $(".hamburger").show();
});
}

function initMap() {
var pip = {
    lat: 22.421645,
    lng: -98.731555
};
var map = new google.maps.Map(document.getElementById("map"), {
    zoom: 13,
    center: pip,
});
var marker = new google.maps.Marker({
    position: pip,
    map: map
});
}

您尝试验证的代码存在语法错误。 这部分:

"env": {
"browser": true,
"node": true,
"jasmine": true    
},

...或者是无关紧要的,或者您没有显示整个摘要。

如果“ env”是一个变量,我认为您需要这样的东西:

env = {
    "browser": true,
    "node": true,
    "jasmine": true
};

适当的缩进将使其更容易阅读

如上文Drew所述,如果env是变量,则需要等号而不是冒号。 另外,您需要声明类型。

const env = {
    "browser": true,
    "node": true,
    "jasmine": true
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM