简体   繁体   English

JSLint:“'HTMLElement'在定义之前就已使用。”

[英]JSLint: “'HTMLElement' was used before it was defined.”

JSLint: "'HTMLElement' was used before it was defined." JSLint:“在定义之前已使用'HTMLElement'。”

if (element instanceof HTMLElement)

How do I fix this? 我该如何解决?

Do I have to add an exception or ignore it? 我必须添加一个例外还是忽略它?

Check "Tolerate misordered definitions". 检查“错误排列错误定义”。

This works for me if my entire script is: 如果我的整个脚本是:

var e;
if (e instanceof HTMLElement) {
    alert("");
}

and the only checked box is "Tolerate misordered definitions". 并且唯一的复选框是“ Tolerate misordered definitions”。

The response I get is: 我得到的答复是:

Global HTMLElement, alert, e

This checkbox only seems to apply to identifiers used in the global scope. 该复选框似乎仅适用于全局范围内使用的标识符。 If this is tried within a function body, JSLint will complain about alert unless you check the box to "Assume console, alert". 如果这是一个函数体内试过,JSLint的会抱怨alert ,除非你选中复选框“假设控制台的警报”。 However the following trick does satisfy JSLint: 但是,以下技巧确实满足了JSLint:

var HTMLElement = HTMLElement;
(function () {
    var e;
    if (e instanceof HTMLElement) {
        alert("");
    }
}());

This passes with checkboxes "Assume console, alert", "Tolerate misordered definitions", and "Tolerate missing use strict." 这与复选框“假设控制台,警报”,“错误排列错误定义”和“严格缺少严格使用情况”复选框一起通过。 I get the response: 我得到答复:

Global HTMLElement  
3 'anonymous'()
    Variable e
    Global HTMLElement
    Complexity 2

Definitely a hack; 绝对是骇客; /*global HTMLElement */ is best. /*global HTMLElement */是最好的。 Makes sense, though, after reading the JSLint instructions. 但是,在阅读了JSLint指令之后,这是有道理的。

Looks like you'll have to add an exception for it. 看来您必须为此添加一个例外。 I could not find any of the checkbox options that remove the error. 我找不到任何消除错误的复选框选项。

You can also add HTMLElement to the predefined textbox at the bottom of the JSLint page (if you are using the online validation version). 您还可以将HTMLElement添加到JSLint页面底部的预定义文本框中(如果使用的是在线验证版本)。

Since I'm assuming you are in a browser this should be a valid exclusion. 由于我假设您使用的是浏览器,因此这应该是有效的排除对象。

将“ alert”更改为“ window.alert”,并在顶部使用jslint指令/ * jslint browser:true * /。

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

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