I’m quite a big fan of refactoring horrible code and getting it as neat and compact as possible, but this shortcut is a bit too far - it gets rid of the simple, familiar, condition part of the for loop and replaces it with something that you may well have to explain with a comment. And though it works when cycling through DOM elements, it will fail for any data array that contains an element that has value false or null.
However, the article where it came from, Simple Tricks for More Usable Forms, is a handy little read, and well worth looking through. I might have a play with some of the hints and tips in it.

Subscribe via RSS











August 12th, 2004 at 13:40:32
Bah! Try Duff’s device (in C):
1. Start with a large loop
X=10213;
for (i=0; i doOtherThing)
X = 10213;
i=0;
switch(X % 10)
{
while(i
August 13th, 2004 at 23:06:08
You raise a couple of good points. It IS really only good for traversing the DOM - which was the reason I blogged it.
The regular DOM traversing loop is probably THE most repetative JS I write and I’ll do anything to save my poor old fingers ;-)