[英]Strange Javascript validation in dreamweaver CC
I've installed Dreamweaver CC 2015 and found out that I have MYRIAD errors in my working JavaScript files. 我安装了Dreamweaver CC 2015,发现我在工作的JavaScript文件中有MYRIAD错误。 Also I have MYRIAD errors in imported JavaScript libraries, including jQuery.
我在导入的JavaScript库中也有MYRIAD错误,包括jQuery。
The most important "error" is this one in the beginning of every working function: 最重要的“错误”是每个工作函数开头的这个错误:
Missing "use strict" statement.
It worked quite well without "use strict" and I've never even seen this statement anywhere. 没有“严格使用”,它工作得很好,我甚至从未在任何地方看到这种说法。
Another strange one is: 另一个奇怪的是:
Extending prototype of native object: 'Array'.
Here is the code which provokes the warning: 以下是引发警告的代码:
Array.prototype.sortOn = function(key){
this.sort(function(a, b){
if(a[key] < b[key]){
return -1;
}else if(a[key] > b[key]){
return 1;
}
return 0;
});
};
So my options are: 所以我的选择是:
What's the best option to go with? 什么是最好的选择? Any help greatly appreciated.
任何帮助非常感谢。
Here's what I figured out. 这是我想出来的。
The problem was that I was not aware of JSHint and JSLint solutions for validating javascript. 问题是我不知道用于验证javascript的JSHint和JSLint解决方案。 JSHint is integrated into Dreamweaver CC and is easily configurable, provided you know what to do.
JSHint已集成到Dreamweaver CC中,并且只要您知道该怎么做,就可以轻松配置。
Normally JSHint has three ways to tweak it , but they don't work in the Dreamweaver environment. 通常,JSHint 有三种方法可以调整它 ,但它们在Dreamweaver环境中不起作用。
What you should do is: 你应该做的是:
JS.jshintrc
will be opened in Dreamweaver. JS.jshintrc
文件将在Dreamweaver中打开。 In my specific case I changed this: 在我的具体情况下,我改变了这个:
"strict":false,
"undef":false,
"unused":false
...which means that I don't have to put "use strict" everywhere and may leave definitions and usage of variables in different files. ...这意味着我不必在任何地方放置“使用严格”,并且可能在不同文件中留下变量的定义和用法。 YES, I don't use wrapper functions and use lots of globals.
是的,我不使用包装函数并使用大量的全局变量。 YES, I know it's bad, but refactoring this is not the highest priority in my schedule.
是的,我知道这很糟糕,但重构这不是我日程安排中的最高优先级。
Of course I will change all three those options to "true" and refactor all my JS files to comply to standards when the time comes. 当然,我会将所有这三个选项更改为“true”,并在时机成熟时重构我的所有JS文件以符合标准。
Turning off the "undef" check is a sledge hammer, as JSHint will then ignore all variable and function name typos. 关闭“undef”检查是一个大锤,因为JSHint将忽略所有变量和函数名称拼写错误。 You won't find the typo until run time, which is annoying and time wasting.
你不会在运行时找到拼写错误,这很烦人,浪费时间。
Rather than disabling the "undef" messages completely, I've been using JSHint Inline Directives near the top of my .js files. 我没有完全禁用“undef”消息,而是在我的.js文件顶部附近使用JSHint内联指令 。 For example:
例如:
/* globals myGlobalVar, myGlobalFunction */
var myLocalVar = myGlobalVar;
myGlobalFunction();
With the globals directive in the file, JSHint will not mark myGlobalVar
or myGlobalFunction()
as undefined errors. 使用文件中的globals指令,
myGlobalVar
不会将myGlobalVar
或myGlobalFunction()
标记为未定义的错误。 Using "globals" inline directives has the added benefit of documenting the dependencies between your .js files. 使用“globals”内联指令还有一个额外的好处,就是记录.js文件之间的依赖关系。
Read about JSHint inline directives here: 在这里阅读JSHint内联指令:
http://jshint.com/docs/#inline-configuration http://jshint.com/docs/#inline-configuration
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.