I disagree on the usage of double quotes over single quotes for strings. Single quotes are useful when the string contains HTML. The Google JavaScript Style guide recommends single quotes over double quotes for this reason: http://google-styleguide.googlecode.com/svn/trunk/javascript...
Front End Development Guidelines
31–40 of 51 posts
Re: Front End Development Guidelines
#32A deep link for those that want to skip my pre-amble: http://taitems.github.com/Front-End-Development-Guidelines/
Re: Front End Development Guidelines
#33A deep link for those that want to skip my pre-amble: http://taitems.github.com/Front-End-Development-Guidelines/
Sorry to point this out, but doesn't your section "@font-face Use and Abuse" rule out embedding typefaces like Gotham?
Re: Front End Development Guidelines
#34I'd like to point out that if jQuery fell back to the fundamental Array.prototype.forEach function when available, $.each would be /much/ faster than a for loop. Array.prototype.forEach, when available, is native code.
Re: Front End Development Guidelines
#35- At the end of the "Always Use === Comparison" section, the example will throw a ReferenceError if (as is suggested) the variable `bar` has not been declared. If you're testing a variable that may not have been declared, you either need to use a `typeof` check or declare bar using `var bar;`, which will be essentially a no-op if bar exists and declares it with a value of `undefined` otherwise.
- The comments example is demonstrating unnecessary comments. The check and the call in
if (zeroAsAString === 0) { doHeapsOfStuff(param1, param2) }
... are self-explanatory to even the an inexperienced developer and do not require comment. What may require comment is why the code performs this check and this call.
- Your array in the "Loop Performance - Use ‘break;’ & ‘continue;’" section has one element. I know it's just an example, but it would be better as an example if it worked. You could instead use
var bigArray = new Array(1000);
- Chaining has downsides, the main one being it makes debugging much harder. You might want to mention this.
Re: Front End Development Guidelines
#36This is good, but some of the advice isn't quite right. For instance "self" is a reserved keyword in JavaScript, so often people use "_self" instead. And camel casing variable names is right, unless they're constants, in which case "THIS_IS_A_CONSTANT" is more appropriate. Too nit picky?
Re: Front End Development Guidelines
#37A deep link for those that want to skip my pre-amble: http://taitems.github.com/Front-End-Development-Guidelines/
Re: Front End Development Guidelines
#38Earlier quoted context omitted.
It's interesting that Google and jQuery seem to disagree on this as per: http://docs.jquery.com/JQuery_Core_Style_Guidelines#Strings I'm yet to see a compelling argument for either. My original paragraph for string creation forgave C style strings, as they do seem very clean cut and easy to identify. I think this is an area that needs some debate.
I think the idea is that if you use single quotes for strings, you don't have to escape the double quotes that are often found in html. ' something ' But the same goes for something like "you can't do that" I guess it just depends what you don't want to escape. For Google, the more probable scenario was probably the former.
Re: Front End Development Guidelines
#39"Javascript code requires regular commenting in order to make it easily understandable." Or you could, you know, just make code that's understandable. I'm such an Internet jerk.
I usually aim to make code that solves the problem it was intended to solve, as elegantly as possible. (Where elegance correlates closely to efficiency.) Whether it's understandable or not is completely secondary. Often this means that if I don't leave myself a reasonable comment about what I'm doing in that spot and why, I'll relearn the importance of good comments later.
Maintainability is quite often the most important thing when it comes to coding not terseness (which many do not consider to be elegant at all, quite the opposite, they see it as unnecessarily complicated and obtuse).
Re: Front End Development Guidelines
#40I disagree on the usage of double quotes over single quotes for strings. Single quotes are useful when the string contains HTML. The Google JavaScript Style guide recommends single quotes over double quotes for this reason: http://google-styleguide.googlecode.com/svn/trunk/javascript...
It's interesting that Google and jQuery seem to disagree on this as per: http://docs.jquery.com/JQuery_Core_Style_Guidelines#Strings I'm yet to see a compelling argument for either. My original paragraph for string creation forgave C style strings, as they do seem very clean cut and easy to identify. I think this is an area that needs some debate.
In C: single quote = character, double-quote = easy initialization of array of characters terminated with \0.
(the above contains many simplifications, of course)