i have write a forEach implemention for understand this Response:
function myForeach(sourch, func) {
for (var i = 0, len = sourch.length; i < len; i++) {
func(sourch[i], i, arr);
}
}
and like forEach, its slow than simple for-loop:
for (var i = 0, len = arr.length; i < len; i++) {
(function(item) {
action(item);
})(arr[i], i, arr); //exactly what foreach dose!
}
here, the two way have function setup & teardown
.
why the for its so faster?