JSLint, The Javascript Verifier
jslint.com
jslint.com
var foo = {
foo: "bar",
bar: "baz",
};
This works in Firefox, but not in IE. Arghhh!Perhaps I should do it Haskell-style:
var foo = { foo: "bar"
, bar: "baz"
};
I find that to be pretty ugly, though, and think it's easier to just omit the trailing comma. Reluctantly.For anyone using Komodo, there's an excellent JSLint plug-in: http://community.activestate.com/xpi/kjslint-jslint-komodo, though you're limited to the version of JSLint they bundle in the plug-in. If you want to manually integrate the latest version into Komodo, I wrote a guide here: http://www.danhulton.com/blog/2008/01/16/integrate-js-lint-i...
Seriously - de-lint your JS.
In vim, I do: :set makeprg=jsl\ -process\ % which binds :make to a syntax check of the current file. It's a cool thing to put in an ftplugin.
if (foo)
bar();
Or is this just a matter of taste as it is with C, C++, Java, C#, etc.?His book ("JavaScript: The Good Parts") contains a lot of good information, but roughly half is what I would consider "style" preferences.
if (foo)
bar();
you might as well write if(foo) bar();
i personally prefer if(foo){bar();}
the reason to be explicit, is incase you are modifying your script via a compressor, sometimes you can not predict what line your code is going to be on, and its always best to be as explicit as possible.if you go to one of Crawford's talks, he mentions how he used to love writing switch case statements with fall through, until he spent hours debugging something because of it. most of the stuff he has in there is a really good start to having fairly readable and reliable code. i recommend following the pattern.
http://www.rockstarapps.com/joomla-1.5.8/products/jslint-ecl...
I still use it - because that trailing-comma-in-hash-definition issue in IE is really annoying.