Re:JSHint: An Community Driven Fork of JSLint
by nailer on Saturday February 19, 2011 @09:19AM
(#2239037)
Hi Paul, got an opinion on http://aresemicolonsnecessaryinjavascript.com ? I'm new to doing JS 'properly' and looking for some guidance here. Thanks.
Re:JSHint: An Community Driven Fork of JSLint
by jacobbijani on Friday February 18, 2011 @02:44PM
(#2236923)
Is there any reference for the reasoning behind error-ing on the standard for loop?
Re:JSHint: An Community Driven Fork of JSLint
by callahad on Friday February 18, 2011 @03:12PM
(#2237032)
It's concerned about the declaration of i within the loop's first term. Since JavaScript only has function-level scope, that variable leaks into the broader context, which can lead to unexpected behavior.
Re:JSHint: An Community Driven Fork of JSLint
by marijn on Friday February 18, 2011 @03:52PM
(#2237213)
Not if you actually, you know, know what you're doing. This dumbing down of programming does not work--if you have clueless people working on code, it'll end up broken, no matter how many tool-enforced 'best practices' they follow.
Re:JSHint: An Community Driven Fork of JSLint
by evgen on Friday February 18, 2011 @11:05PM
(#2238336)
Why would the zen master of JavaScript of which you speak have any need for JSLint in the first place? Us mere mortals are sometimes forgetful and need reminders...
Re:JSHint: An Community Driven Fork of JSLint
by Skalman on Friday February 18, 2011 @04:31PM
(#2237355)
I can't see why people not liking the defaults (which are great for beginners) can't change their settings.
Re:JSHint: An Community Driven Fork of JSLint
by daleharvey on Friday February 18, 2011 @02:53PM
(#2236956)
Problem at line 1 character 6: Move 'var' declarations to the top of the function.
I do prefer having all my vars at the top of the function, loop vars are an exception though.
Re:JSHint: An Community Driven Fork of JSLint
by isak2 on Friday February 18, 2011 @03:28PM
(#2237106)
I think Crockford is right about that error.
Declaration of variables in the loop could lead to this type of error:
http://cam.ly/blog/2011/01/javascript-interview-question/
(All of the 4 <li> will do alert('4') when clicked, when the programmer expects alert('1'), alert('2'), etc.)
If the variable had been declared at the top, that error probably would not happen.
Re:JSHint: An Community Driven Fork of JSLint
by daleharvey on Friday February 18, 2011 @03:37PM
(#2237144)
That error would have happened despite if the var was declared at the top or in the loop
addEventListener("stuff", function() {
return function(index) {
alert(index);
}
}(i);
is the fix, either way
However, JSLint has gotten increasingly more opinionated in the past few months.. For example, the standard for loop: `for (var i = 0, len = arr.length; i < len; i++) { ... ` will now error out in JSLint.
A lot of these sorts of changes don't have flags to customize, so that's something that JSHint aims to fix. Start with some great defaults, and allow them to be customized. Heck, we even save your checkbox preferences for you (via localStorage).
Crock's responses to people asking for changes on the mailing list have also been a little disappointing:
"Your sadly pathetic bleatings are harshing my mellow." http://tech.groups.yahoo.com/group/jslint_com/message/1688
On the github project, he's refused CommonJS convention, NodeJS export support, and Rhino compat -- all quite easy to do. So until Crock's primary JSLint is a bit more friendly to customizability and different environments, JSHint will fulfill those needs.