Do not use Array.prototype.forEach for potentially large arrays

This commit is contained in:
Andreas Hocevar
2017-07-29 23:10:53 +02:00
parent 2258c00fca
commit 1b46f38696
3 changed files with 13 additions and 5 deletions
+5 -1
View File
@@ -95,7 +95,11 @@ ol.Collection.prototype.extend = function(arr) {
* @api
*/
ol.Collection.prototype.forEach = function(f, opt_this) {
this.array_.forEach(f, opt_this);
var fn = (opt_this) ? f.bind(opt_this) : f;
var array = this.array_;
for (var i = 0, ii = array.length; i < ii; ++i) {
fn(array[i], i, array);
}
};