admin管理员组文章数量:1389768
JSLint: "'HTMLElement' was used before it was defined."
if (element instanceof HTMLElement)
How do I fix this?
Do I have to add an exception or ignore it?
JSLint: "'HTMLElement' was used before it was defined."
if (element instanceof HTMLElement)
How do I fix this?
Do I have to add an exception or ignore it?
Share Improve this question edited Mar 1, 2013 at 0:34 ThinkingStiff 65.4k30 gold badges147 silver badges241 bronze badges asked Aug 20, 2011 at 13:44 XP1XP1 7,1938 gold badges59 silver badges63 bronze badges4 Answers
Reset to default 6Check "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".
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 plain about alert
unless you check the box to "Assume console, alert". However the following trick does satisfy 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. Makes sense, though, after reading the JSLint instructions.
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).
Since I'm assuming you are in a browser this should be a valid exclusion.
change "alert" to "window.alert", and use the jslint directive /*jslint browser:true */ at the top.
本文标签: javascriptJSLint quot39HTMLElement39 was used before it was definedquotStack Overflow
版权声明:本文标题:javascript - JSLint: "'HTMLElement' was used before it was defined." - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744608531a2615509.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论