You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/05-data-types/06-iterable/article.md
+2-18Lines changed: 2 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,17 +28,10 @@ let range = {
28
28
29
29
Pour rendre la `range` itérable (et donc laisser `for..of` faire sont travail), nous devons ajouter une méthode à l'objet nommé `Symbol.iterator` (un symbole intégré spécial que pour cela).
30
30
31
-
<<<<<<< HEAD
32
31
1. Lorsque `for..of` démarre, il appelle cette méthode une fois (ou des erreurs si il n'est pas trouvé). La méthode doit retourner un *iterator* -- un objet avec la méthode `next`.
33
32
2. À partir de là, `for..of` ne fonctionne *qu'avec cet objet retourné*.
34
33
3. Quand `for..of` veut la valeur suivante, il appelle `next()` sur cet objet.
35
-
4. Le résultat de `next()` doit avoir la forme `{done: Boolean, valeur: any}`, où `done = true` signifie que l'itération est terminée, sinon `value` doit être la nouvelle valeur.
36
-
=======
37
-
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`.
38
-
2. Onward, `for..of` works *only with that returned object*.
39
-
3. When `for..of` wants the next value, it calls `next()` on that object.
40
-
4. The result of `next()` must have the form `{done: Boolean, value: any}`, where `done=true` means that the loop is finished, otherwise `value` is the next value.
41
-
>>>>>>> 71da17e5960f1c76aad0d04d21f10bc65318d3f6
34
+
4. Le résultat de `next()` doit avoir la forme `{done: Boolean, value: any}`, où `done = true` signifie que l'itération est terminée, sinon `value` doit être la nouvelle valeur.
42
35
43
36
Voici l'implémentation complète de `range` avec les remarques :
44
37
@@ -51,13 +44,8 @@ let range = {
51
44
// 1. l'appel d'un for..of appelle initialement ceci
52
45
range[Symbol.iterator] =function() {
53
46
54
-
<<<<<<<HEAD
55
47
// ...il retourne l'objet itérateur:
56
-
// 2. À partir de maintenant, for..of fonctionne uniquement avec cet itérateur, lui demandant les valeurs suivantes
57
-
=======
58
-
// ...it returns the iterator object:
59
-
// 2. Onward, for..of works only with the iterator object below, asking it for next values
60
-
>>>>>>>71da17e5960f1c76aad0d04d21f10bc65318d3f6
48
+
// 2. À partir de là, for..of fonctionne uniquement avec cet itérateur, lui demandant les valeurs suivantes
61
49
return {
62
50
current:this.from,
63
51
last:this.to,
@@ -282,11 +270,7 @@ for (let char of str) {
282
270
alert(chars);
283
271
```
284
272
285
-
<<<<<<< HEAD
286
273
...Mais c'est plus court.
287
-
=======
288
-
...But it is shorter.
289
-
>>>>>>> 71da17e5960f1c76aad0d04d21f10bc65318d3f6
290
274
291
275
Nous pouvons même créer une substitution-consciente de `slice` sur elle:
0 commit comments