This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(forEach): use native for loop instead of forEach for Arrays
- Loading branch information
36625de
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @IgorMinar
This change landed in 1.3.x but not in 1.2.x. Any specific reason?
36625de
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
36625de
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Thanks for replying. But this will eventually land in 1.2, right? :)
36625de
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IgorMinar
What do you think about adding a new condition here
...
else if (isArray(obj) || isArrayLike(obj)) {
for (key = 0, length = obj.length; key < length; key++) {
if ( typeof obj[key] !== 'undefined' ) { // ADDED
iterator.call(context, obj[key], key);
}
}
...
to work on sparse arrays, too ?
36625de
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just test if the value is undefined in your iterator function if you care about that? (ES5 forEach doesn't care if the property value is undefined or not)