3 ms·
I'm all about making sure that code is optimized for humans first and computers second. Here is the specific remark I was referring to: Or even better, just us
by couchand 12y ago
I'm all about making sure that code is optimized for humans first and computers second.
Here is the specific remark I was referring to: Or even better, just use .forEach which doesn't have the same caveats as declaring functions in for loops.
Blindly applying forEach is simply not the right answer here.
- nailer 12y agoI'd suggest the opposite: forEach() is smaller that iterating over indexes and creates a scope by default which (although having overhead) will prevent a lot of common last-case-wins scenarios that frequently trap both new and experienced developers. Should we use a .forEach() for a 1 million item array? No. Performance would be a problem. For the typical use case of items like the demo [1, 2, 3]? Yes, this would be be simpler.