caolan/async — Issue #97: Increase performance throughout async by optimizing definitions of cross-browser functions
Author: debonet
Created: 2012-02-17 15:26:14+00:00
State: open

Performance can be improved by changing definition of cross browser functions `_forEach(), _map(), _reduce(), _keys(), _indexOf()` to first check if built in exists then define. E.g., instead of:

var _forEach = function (arr, iterator) {
if (arr.forEach) {
return arr.forEach(iterator);
}
for (var i = 0; i < arr.length; i += 1) {
iterator(arr[i], i, arr);
}
};

use:

var _forEach = (
Array.prototype.forEach
? function (arr, iterator) {
return arr.forEach(iterator);
}
: function (arr, iterator) {
for (var i = 0; i < arr.length; i += 1) {
iterator(arr[i], i, arr);
}
);