views:

3231

answers:

6

What are the established coding standards for JavaScript?

+7  A: 

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

LBugnion
This document has reference to 'C# programming guidelines'. Do you have it publicly available as well?
z-boss
+4  A: 

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.

aemkei
+12  A: 

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:

http://developer.mozilla.org/en/JavaScript_style_guide

http://neil.rashbrook.org/Js.htm

Gene T
+5  A: 

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/

Remy Sharp
There is also JSLint to help automate/verify some of these guidelines. http://www.jslint.com/
Funka
+1  A: 

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.

http://jibbering.com/faq/notes/code-guidelines/

Garrett
A: 

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

Simon