Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/413.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 缩小后我是否应该删除代码?_Javascript_Jslint_Jshint_Uglifyjs - Fatal编程技术网

Javascript 缩小后我是否应该删除代码?

Javascript 缩小后我是否应该删除代码?,javascript,jslint,jshint,uglifyjs,Javascript,Jslint,Jshint,Uglifyjs,我有一些javascript可以在缩小之前通过筛选,但不能在缩小之后通过筛选。 我是否应该担心以下错误/警告: "Expected an assignment or function call and instead saw an expression" "Use '!==' to compare with 'null'" "Don't make functions within a loop" "Missing '()' invoking a constructor." "Expected a

我有一些javascript可以在缩小之前通过筛选,但不能在缩小之后通过筛选。 我是否应该担心以下错误/警告:

"Expected an assignment or function call and instead saw an expression"
"Use '!==' to compare with 'null'"
"Don't make functions within a loop"
"Missing '()' invoking a constructor."
"Expected a conditional expression and instead saw an assignment"
"Confusing use of '!'"
"A leading decimal point can be confused with a dot: '.5'"
"Expected an operator and instead saw ','"
"Expected an identifier and instead saw '}'"
"Expected ')' to match '(' from line 9 and instead saw '{'"
"Expected an identifier and instead saw '='"

我想你对删除代码的作用感到困惑。linter的目的是防止容易出现人为错误的编程风格。缩微器的作用是压缩源代码,使其具有尽可能少的字符

缩小后的Linting是毫无意义的(您永远不应该手动更改缩小的代码,这样就不会有人为错误),如果您选择“修复”缩小的代码,甚至是有害的,因为它会增加大小


使用这些工具的正确方法是删除代码,以删除容易出现人为错误的常见模式,然后将其缩小到生产所需的最小值。如果您想检查缩微器的正确性,您需要使用测试,在缩微过程之前和之后测试代码,结果应该是相同的。请记住,根据minifier的攻击性,可以完全删除未使用的代码,可以内联函数,等等,因此测试minified代码绝对不是一件小事。

在测试之前和之后,您使用什么来删除?不同的应用程序(jshint和在线jslint)?您使用的是不同的选项集吗?我不使用任何选项,无论是在显示某个源代码之前还是之后,但在我看来,“缩小”可能会去掉一些大括号,而不仅仅是分号。如果您有一个js格式的IDE,请重新格式化并检查错误。这样,你就可以看到脚本缩小的正确性了。好吧,我的js真的很长。但我的问题更多:在缩小代码后对代码进行lint是一件常见的事情吗?“linter的目的是防止容易出现人为错误的编程风格”。说得好,非常感谢。