-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Some code uses $.each, some uses Array.prototype.forEach #1098
Comments
Most instances of |
Cool, that makes good sense. I suppose anyone that comes across this ticket may also consider: var obj = { a: "alpha", b: "beta" };
Object.keys( obj ).forEach(function( key ) {
// since the |thisArg| was used, |this| is `obj`
console.log( this[ key ] );
}, obj);
// alpha
// beta |
Hmmm, according to this jsPerf |
It's true, the bottle neck is at 2 major points:
[ 1, 2, , 4, , , , ].forEach(function(val) { console.log(val); })
// 1
// 2
// 4 The downside to |
@njx: I'm all for that (har!) for very hot performance-sensitive code, but we should be wary of premature optimization elsewhere. All the flavors of loops are very fast, and the loop overhead will almost always pale in comparison to the cycles eaten up by whatever the body of the loop is doing. I ran some tests on this way back when we were originally talking over coding style. I had a simple test of walking a 10,000-item array 100 times in a row (with a loop body that was barely more than a no-op). In that test, forEach() was 120 ms slower than a vanilla for loop -- hardly nothing, but if we have any code that expects to do 1 million iterations fast I hope we'd be thinking carefully enough about it to consider switching the loop type :-) |
Yup. In any case, the original bug still stands :) |
Reviewed - @RaymondLim - Ray please work with Peter on this bug. |
Move to sprint 12 as we need some more cleanup pointed out by @peterflynn in #1287. |
Moving to Sprint 13 -- Raymond won't have time to finish this, and it's just a non-critical code cleanup |
This requires changes to many files. So moving to the next sprint again. |
Much like the
Array.isArray
in #1096If this is meant to be used with modern browsers only, then I would expect Array.prototype.forEach to be preferred.
The text was updated successfully, but these errors were encountered: