JavaScript Concern from a recent review

Colin Ogilvie bugzilla at colinogilvie.co.uk
Sun Apr 8 17:46:31 UTC 2007


bugzilla-daemon at mozilla.org wrote:
> Nit: omit braces for one-line conditional and loop blocks here and elsewhere,
> i.e.:
>
> 	for (var i = 0; i < document.forms.length; i++)
> 	    for (var j = 0; j < document.forms[i].elements.length; j++)
> 		/* MS decided to add fieldsets to the elements array; and
> 		 * Mozilla decided to copy this brokenness. Grr.
> 		 */
> 		if (document.forms[i].elements[j].tagName != 'FIELDSET')
> 		    document.forms[i].elements[j].onmouseover = showHelp;

I'm concerned by a recent review Myk did on a JavaScript file (quoted 
above) where he says that for one-line conditionals and loop blocks you 
should omit braces (as a Nit).

I'd like to suggest that this is a bad practice, and possibly going to 
cause confusion in the future, particularly in the example above. For 
clarity, it would be better written including braces.

Does anyone else have thoughts on this, or is it just because I've been 
bitten by this in something I was doing at work...

Colin




More information about the developers mailing list