Document for-in restricted usage

https://github.com/airbnb/javascript/issues/851#issuecomment-213834028
This commit is contained in:
Cédric Malard
2016-07-06 17:00:42 +02:00
committed by GitHub
parent 7816731d4d
commit 7fb8b03714

View File

@@ -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];