Skip to content

Commit 5ecfdf6

Browse files
committed
fixes
1 parent bbf98b2 commit 5ecfdf6

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

1-js/05-data-types/06-iterable/article.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
*Iterable* objects is a generalization of arrays. That's a concept that allows to make any object useable in a `for..of` loop.
55

6-
Of course, Arrays are iterable. But there are many other built-in objects, that are iterable as well. For instance, Strings are iterable also. As we'll see, many built-in operators and methods rely on them.
6+
Of course, Arrays are iterable. But there are many other built-in objects, that are iterable as well. For instance, strings are also iterable.
77

8-
If an object represents a collection (list, set) of something, then `for..of` is a great syntax to loop over it, so let's see how to make it work.
8+
If an object isn't technically an array, but represents a collection (list, set) of something, then `for..of` is a great syntax to loop over it, so let's see how to make it work.
99

1010

1111
## Symbol.iterator
@@ -31,9 +31,9 @@ To make the `range` iterable (and thus let `for..of` work) we need to add a meth
3131
1. When `for..of` starts, it calls that method once (or errors if not found). The method must return an *iterator* -- an object with the method `next`.
3232
2. Onward, `for..of` works *only with that returned object*.
3333
3. When `for..of` wants the next value, it calls `next()` on that object.
34-
4. The result of `next()` must have the form `{done: Boolean, value: any}`, where `done=true` means that the iteration is finished, otherwise `value` must be the new value.
34+
4. The result of `next()` must have the form `{done: Boolean, value: any}`, where `done=true` means that the iteration is finished, otherwise `value` is the next value.
3535

36-
Here's the full implementation for `range`:
36+
Here's the full implementation for `range` with remarks:
3737

3838
```js run
3939
let range = {
@@ -68,10 +68,10 @@ for (let num of range) {
6868
}
6969
```
7070

71-
Please note the core feature of iterables: an important separation of concerns:
71+
Please note the core feature of iterables: separation of concerns.
7272

7373
- The `range` itself does not have the `next()` method.
74-
- Instead, another object, a so-called "iterator" is created by the call to `range[Symbol.iterator]()`, and it handles the whole iteration.
74+
- Instead, another object, a so-called "iterator" is created by the call to `range[Symbol.iterator]()`, and its `next()` generates values for the iteration.
7575

7676
So, the iterator object is separate from the object it iterates over.
7777

@@ -140,9 +140,7 @@ for (let char of str) {
140140

141141
## Calling an iterator explicitly
142142

143-
Normally, internals of iterables are hidden from the external code. There's a `for..of` loop, that works, that's all it needs to know.
144-
145-
But to understand things a little bit deeper let's see how to create an iterator explicitly.
143+
For deeper understanding let's see how to use an iterator explicitly.
146144

147145
We'll iterate over a string in exactlly the same way as `for..of`, but with direct calls. This code creates a string iterator and gets values from it "manually":
148146

@@ -283,7 +281,7 @@ let str = '𝒳😂𩷶';
283281

284282
alert( slice(str, 1, 3) ); // 😂𩷶
285283

286-
// native method does not support surrogate pairs
284+
// the native method does not support surrogate pairs
287285
alert( str.slice(1, 3) ); // garbage (two pieces from different surrogate pairs)
288286
```
289287

0 commit comments

Comments
 (0)