I had a chance to work with Cody on the jQuery Cookbook, and he's a smart guy. So Cody, if you see this, my apologies for poking fun at your new book's mobile experience!
My chapter of the jQuery Cookbook had a much bigger blunder. In a "recipe" called Coding Bare-Metal Loops, I recommended a particular loop style as the ultimate in speed...
> Use a for loop instead of .each(). To iterate over an array, it’s hard to beat this loop:
for( var item, i = −1; item = array[++i] ) {
// do stuff with item
}
> But there is a catch: this loop works only if your array has no “false” elements, that is, elements whose value is undefined, null, false, 0, or "". Even with that restriction, this loop is useful in many common cases, such as iterating over a jQuery object.Well... It didn't quite turn out that way. This loop style can kick you out of the optimizer because it tries to access the nonexistent element after the end of the array. That's perfectly legal in JavaScript, of course - any nonexistent element evaluates as undefined - but code optimizers do not like it when you do that.
So a conventional loop turned out to be much faster: