What are the established coding standards for JavaScript?
Hi,
I never saw a widely acknowledged JavaScript coding standard out there. We did write our own some time ago and I published it on my blog in accordance with my employer.
http://blog.galasoft.ch/archive/2007/02/05/105493.aspx
Keep in mind that some of the guidelines might be a bit outdated.
Cheers, Laurent
You can find some simple but essential coding conventions at the Google Code Wiki.
For very detailed style guides read the Dojo Style Guide. It is going over naming conventions, file conventions, variable usage, code layout, whitespace, and comments.
not exactly what you're looking for, but (like Doug Crockford's vids) i think everybody who writes/edits/reviews JS should look at Chris Heilmann's slides and videos on maintainable javascript:
http://ajaxian.com/archives/maintainable-javascript-videos-are-now-available
in the slides: http://www.slideshare.net/cheilmann/fronteers-maintainability-presentation , slide 127, he says don't worry so much about style guides/code standards, reformat all code checked in to VCS.
Also these:
Another reason why Crockford's JavaScript coding guidelines are a good idea to follow:
This code (below) actually returns undefined because of JavaScript's semicolon injection - which is a damn good reason to get the whole team of developers singing from the same song sheet:
return // injected semicolon, therefore returns 'undefined'
{
javascript : "fantastic"
}; // object constructs anonymously but nothing happens with it.
Bit more about that here: http://www.robertnyman.com/2008/10/16/beware-of-javascript-semicolon-insertion/
The comp.lang.javascript Code Guidelines document points to causes of errors and problems related to javascript for web applications and how to avoid them.
Myself and a few others recently put together these; http://www.asp.net/ajaxlibrary/act_contribute_codingStandards.ashx (PDF or HTML)
They are primarily intended for use with the Ajax Control Toolkit but realistically contain all sorts of useful guidance whichever framework you use.
Hope that helps. Simon