News for hackers. Stuff that matters.
Re:Front End Development Guidelines by warfangle on Friday May 06, 2011 @01:04AM (#2520060)
I'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 by timdown on Friday May 06, 2011 @04:56AM (#2520405)
No. forEach() being native doesn't prevent it from generally being slower than a foor loop, because it still has to do a function call on every iteration.
Re:Front End Development Guidelines by warfangle on Friday May 06, 2011 @11:50AM (#2521279)
It depends on what you're doing within the loop. With a for loop, you still have to perform an array lookup. For something simple, like summing up all the numbers in an array, forEach is definitely faster. Try JSLitmus'ing it.
Re:Front End Development Guidelines by swanson on Friday May 13, 2011 @12:01PM (#2545071)
This is how underscore.js implements each()