-
-
Save CWSpear/3874431 to your computer and use it in GitHub Desktop.
{ | |
"bitwise": true, | |
"eqeqeq": true, | |
"latedef": true, | |
"newcap": true, | |
"noarg": true, | |
"nonew": true, | |
"regexp": true, | |
"trailing": true, | |
"regexdash": true, | |
"sub": true, | |
"browser": true, | |
"devel": true, | |
"jquery": true | |
} |
(Replying here to have more than 140 characters)
You're getting two different warnings. First one, Missing 'new' prefix when invoking constructor.
is triggered whenever JSHint notices that you're calling a capitalized function without new
. It is a purely stylistic warning—Crockford (I think) made that convention to easily distinguish constructors from other functions since calling a constructor without new
can leak stuff into the global scope unless you're in a strict mode. The check is off by default and you can turn it on with newcap:true
(as you did in the config above).
The second warning is about using a constructor for side-effects. Even thought it is legal (and can be helpful in minority of cases) the result of calling a constructor is supposed to be assigned to a variable. When you don't do that JSHint thinks that there is a possibility of a typo and issues a warning. The check is off by default and you can turn it on with nonew:true
(as you did in the config above).
So basically your configuration is very strict about the use of capitalized functions. It prohibits the use of capitalized functions without new and requires results of that expression to be assigned to a variable. In your case Cycle
is not a constructor function so I'd either rename it to cycle
or remove newcap
and nonew
.
Ok, that makes great sense, thank you.
I remember now that I set newcap
to true because I like the convention of classes being Capitalized and I use it across all my own code, but I'm collaborating with another developer on this one, and his company are all Windows developers and a lot of the style and conventions have been very different than anything I use, but I am trying to match their styling. So this wouldn't have normally been an issue in my own code.
Since this is used in a JavaScript context, comments were valid, but as pure JSON, it's invalid, so I removed them.