mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 07:47:54 -05:00
Document for-in restricted usage
https://github.com/airbnb/javascript/issues/851#issuecomment-213834028
This commit is contained in:
@@ -1215,10 +1215,12 @@ Other Style Guides
|
||||
## Iterators and Generators
|
||||
|
||||
<a name="iterators--nope"></a><a name="11.1"></a>
|
||||
- [11.1](#iterators--nope) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html)
|
||||
- [11.1](#iterators--nope) Don't use iterators. Prefer JavaScript's higher-order functions instead of loops like `for-in` or `for-of`. eslint: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html) [`no-restricted-syntax`](http://eslint.org/docs/rules/no-restricted-syntax)
|
||||
|
||||
> Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects.
|
||||
|
||||
> Use `map()` / `every()` / `filter()` / `find()` / `findIndex()` / `reduce()` / `some()` / ... to iterate over arrays, and `Object.keys()` / `Object.values()` / `Object.entries()` to produce arrays so you can iterate over objects.
|
||||
|
||||
```javascript
|
||||
const numbers = [1, 2, 3, 4, 5];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user