Skip to content

Commit da0a19a

Browse files
authored
docs(array-foreach): clarify chaining exceptions
1 parent 26f0686 commit da0a19a

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

docs/rules/array-foreach.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ The problem we now have is that we're iterating multiple times over the items in
5050
}
5151
```
5252

53+
Chaning isn't always necessarily bad. Chaining can advertise a series of transformations that are independant from one another, and therefore aid readability. Additionally, sometimes the "goto-style" behaviour of `continue` in for loops can hamper readability. For small Arrays, performance is not going to be of concern, but caution should be applied where there is a potentially unbounded Array (such as iterating over a fetched users list) as performance can easily become a bottleneck when unchecked.
54+
5355
### Hiding Intent
5456

5557
The `forEach` method passes more than just the current item it is iterating over. The signature of the `forEach` callback method is `(cur: T, i: Number, all: []T) => void` and it can _additionally_ override the `receiver` (`this` value), meaning that often the _intent_ of what the callback does is hidden. To put this another way, there is _no way_ to know what the following code operates on without reading the implementation: `forEach(polishApple)`.

0 commit comments

Comments
 (0)