admin管理员组

文章数量:1287517

I've installed Dreamweaver CC 2015 and found out that I have MYRIAD errors in my working JavaScript files. Also I have MYRIAD errors in imported JavaScript libraries, including 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:

  1. Ditch Dreamweaver and use another IDE (the worst, because it works perfectly fine for my purposes - I'm sole HTML/CSS/JS/PHP/MySQL developer in my project.
  2. Fix all errors like Dreamweaver wants, because it has a good point. Then please explain why? I'm OK with changing "==" to "===", adding "var" before variable declarations, not using "return" after "if" without curly braces, but that "use strict" thing bothers me.
  3. Tweak the JavaScript validation, so only critical errors are shown - the best option for me - but I don't know HOW to do it?

What's the best option to go with? Any help greatly appreciated.

I've installed Dreamweaver CC 2015 and found out that I have MYRIAD errors in my working JavaScript files. Also I have MYRIAD errors in imported JavaScript libraries, including 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:

  1. Ditch Dreamweaver and use another IDE (the worst, because it works perfectly fine for my purposes - I'm sole HTML/CSS/JS/PHP/MySQL developer in my project.
  2. Fix all errors like Dreamweaver wants, because it has a good point. Then please explain why? I'm OK with changing "==" to "===", adding "var" before variable declarations, not using "return" after "if" without curly braces, but that "use strict" thing bothers me.
  3. Tweak the JavaScript validation, so only critical errors are shown - the best option for me - but I don't know HOW to do it?

What's the best option to go with? Any help greatly appreciated.

Share Improve this question edited Jul 5, 2015 at 12:33 user663031 asked Jul 4, 2015 at 14:15 Megan CaithlynMegan Caithlyn 3832 gold badges11 silver badges34 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 11

Here's what I figured out.

The problem was that I was not aware of JSHint and JSLint solutions for validating javascript. JSHint is integrated into Dreamweaver CC and is easily configurable, provided you know what to do.

Normally JSHint has three ways to tweak it, but they don't work in the Dreamweaver environment.

What you should do is:

  • From the top menu select Edit -> Preferences (Dreamweaver -> Preferences on Mac)
  • Choose "Linting" from the side menu.
  • Select "JS" and click "Edit and save changes".
  • The file JS.jshintrc will be opened in Dreamweaver.
  • Edit the file like you normally would (see JSHint options) and save.

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 ply to standards when the time es.

Turning off the "undef" check is a sledge hammer, as JSHint will then ignore all variable and function name typos. You won't find the typo until run time, which is annoying and time wasting.

Rather than disabling the "undef" messages pletely, I've been using JSHint Inline Directives near the top of my .js files. 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. Using "globals" inline directives has the added benefit of documenting the dependencies between your .js files.

Read about JSHint inline directives here:

http://jshint./docs/#inline-configuration

本文标签: Strange Javascript validation in dreamweaver CCStack Overflow