3 ms·
i agree with the choice of code, but I have a different style for laying out the code. i dislike the declaration and immediate execution of an anonymous functi
by aaronblohowiak 16y ago
i agree with the choice of code, but I have a different style for laying out the code.
i dislike the declaration and immediate execution of an anonymous function. i much prefer to give it a name, move it out of the loop itself and then call it within the loop. it makes reading the code more top-to-bottom.
with this approach, when I get to the anon func declaration, i have to scan down looking for when it is invoked. while indentation helps, i then have to backtrack up to the beginning of the func declaration.. and hopefully i haven't lost track of what the execution context for the anon func is and so forth...
- lhorie 16y agoI don't generally care too much to talk about style when the problem at hand is that someone has been banging their head against the desk for the past two hours and they just want it to work (and, in my experience, this usually is the case, for some reason) But yeah, if we're gonna be super nitpicky, yeah sure, improve the for loop also, while we're at it. for (var i = -1; els[++i];) {//given the code in the loop body, this is shorter and faster