Created
October 11, 2012 18:17
-
-
Save CWSpear/3874431 to your computer and use it in GitHub Desktop.
My JSHint Settings (used in CodeKit and Sublime Text 2 via SublimeLinter)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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 | |
} |
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(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 withoutnew
. It is a purely stylistic warning—Crockford (I think) made that convention to easily distinguish constructors from other functions since calling a constructor withoutnew
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 withnewcap: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 tocycle
or removenewcap
andnonew
.