gpt4 book ai didi

javascript - 我应该担心 HTML5Shiv.min.js 版本 3.7.2 上的这些 JSLint 警告吗?

转载 作者:行者123 更新时间:2023-11-30 10:05:56 25 4
gpt4 key购买 nike

我从这个 Cloudflare 复制了一个 HTML5Shiv.min.js 版本链接,当我将文件导入 Adob​​e Brackets 时,JSLint 编译器告诉我脚本包含以下错误:

4   Missing 'use strict' statement.
!function (a, b) {function c(a, b) {var c = a.createElement("p"), d = a.getElementsByTagName("head")[0] || a.documentElement; return c.innerHTML="x<style>"+b+"</style>",d.ins

4 'c' is already defined.
!function (a, b) {function c(a, b) {var c = a.createElement("p"), d = a.getElementsByTagName("head")[0] || a.documentElement; return c.innerHTML="x<style>"+b+"</style>",d.ins

4 Expected ';' and instead saw '='.
!function (a, b) {function c(a, b) {var c = a.createElement("p"), d = a.getElementsByTagName("head")[0] || a.documentElement; return c.innerHTML="x<style>"+b+"</style>",d.ins

4 Unreachable '=' after 'return'.
!function (a, b) {function c(a, b) {var c = a.createElement("p"), d = a.getElementsByTagName("head")[0] || a.documentElement; return c.innerHTML="x<style>"+b+"</style>",d.ins

4 Expected an identifier and instead saw '='.
!function (a, b) {function c(a, b) {var c = a.createElement("p"), d = a.getElementsByTagName("head")[0] || a.documentElement; return c.innerHTML="x<style>"+b+"</style>",d.ins

4 Stopping. (100% scanned).
!function (a, b) {function c(a, b) {var c = a.createElement("p"), d = a.getElementsByTagName("head")[0] || a.documentElement; return c.innerHTML="x<style>"+b+"</style>",d.ins

如果我决定使用它,它真的有用吗?缺少语句和无法访问的运算符的代码。也许 JSLint 不是最新的或者某些东西已经关闭,但如果可能的话,我想就此征求第二意见。

谢谢。

最佳答案

别着急。你可以使用图书馆。唯一“缺失”的行是 “use strict”;,这是 JSLint 喜欢的内容,但您不需要使用它。 ( Here's a decent discussion of use strict .)

JSLint 和其他 linters 寻找两种类型的“错误”:功能性风格。 JSLint 发现的许多样式错误实际上会转化为您希望避免的逻辑错误。这是一个很棒的工具。

同时,您可以在不破坏代码功能的情况下犯下 JSLint 不喜欢的样式错误,尤其是在压缩代码中。当您看到 JSLint 识别第三方代码或任何人的缩小代码中的样式错误时,请不要担心。它们不一定是功能性问题。

通常,您应该从 linting 中排除第 3 方库。对于外部库,您无能为力,除非您想自己 fork 它们并对其进行 lint,这很疯狂。 ;^) 而且,再一次,缩小代码通常采用对 lint 不友好的快捷方式。在缩小之前检查您的代码以保持其高质量,但不要担心您无论如何都不应该接触的 QAing 库。假设他们有另一种确保高质量的方法,这可能包括使用不同的 linter,或具有不同规则集的 linter。

这是一个“肮脏”的 secret ......

jQuery borks JSLint 也...

jQuery, even unminified ,例如,也不掉毛。即使我添加一行告诉 JSLint 去掉空白“error”,缺少“use strict”,并让它知道它应该假设一个浏览器,我得到...

'module' was used before it was defined.
if ( typeof module === "object" && typeof module.exports === "object" ) {
line 18 character 44'module' was used before it was defined.
if ( typeof module === "object" && typeof module.exports === "object" ) {
line 26 character 3'module' was used before it was defined.
module.exports = global.document ?
line 39 character 3Unexpected 'typeof'. Use '===' to compare directly with undefined.
}(typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
line 49 character 5 Combine this with the previous 'var' statement.
var slice = deletedIds.slice;
line 51 character 5 Combine this with the previous 'var' statement.
var concat = deletedIds.concat;
line 53 character 5 Combine this with the previous 'var' statement.
var push = deletedIds.push;
line 55 character 5 Combine this with the previous 'var' statement.

等等等等。没有人会说 jQuery 是假的,你知道吗?所以如果 Cloudfire 或任何其他文件给你同样的错误集,请不要担心。

底线:不要担心 lint 对你大喊大叫关于库,尤其是缩小的库。 Linter 是您的 代码的代码质量工具。如果其他人有其他方法来保持他们的代码正常工作并且它可以很好地测试您的使用,请不要管 lib。 ;^)

关于javascript - 我应该担心 HTML5Shiv.min.js 版本 3.7.2 上的这些 JSLint 警告吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29177993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com