Skip to content

Commit 937fe0b

Browse files
authored
Merge pull request #49 from TevaHenry/master
Translate "Arrow functions revisited" into French
2 parents ab94fd7 + 201ea6b commit 937fe0b

File tree

1 file changed

+37
-37
lines changed
  • 1-js/06-advanced-functions/12-arrow-functions

1 file changed

+37
-37
lines changed
Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
# Arrow functions revisited
1+
# Les fonctions fléchées revisitées
22

3-
Let's revisit arrow functions.
3+
Revisitons les fonctions fléchées.
44

5-
Arrow functions are not just a "shorthand" for writing small stuff.
5+
Les fonctions fléchées ne sont pas simplement un "raccourci" pour écrire moins de choses.
66

7-
JavaScript is full of situations where we need to write a small function, that's executed somewhere else.
7+
JavaScript est plein de situations où nous avons besoin d'écrire une petite fonction, exécutée ailleurs.
88

9-
For instance:
9+
Par exemple:
1010

11-
- `arr.forEach(func)` -- `func` is executed by `forEach` for every array item.
12-
- `setTimeout(func)` -- `func` is executed by the built-in scheduler.
13-
- ...there are more.
11+
- `arr.forEach(func)` - - `func` est exécuté par `forEach` pour chaque élément du tableau.
12+
- `setTimeout(func)` - - `func` est exécuté par le planificateur intégré.
13+
- ...il y en a plus encore.
1414

15-
It's in the very spirit of JavaScript to create a function and pass it somewhere.
15+
C'est dans l'esprit même de JavaScript de créer une fonction et de la transmettre quelque part.
1616

17-
And in such functions we usually don't want to leave the current context.
17+
Et dans de telles fonctions, nous ne voulons généralement pas quitter le contexte actuel.
1818

19-
## Arrow functions have no "this"
19+
## Les fonctions fléchées n'ont pas de "this"
2020

21-
As we remember from the chapter <info:object-methods>, arrow functions do not have `this`. If `this` is accessed, it is taken from the outside.
21+
AComme nous nous en souvenons du chapitre <info:object-methods>, les fonctions fléchées n'ont pas de `this`. Si on accède à `this`, il est pris de l'extérieur.
2222

23-
For instance, we can use it to iterate inside an object method:
23+
Par exemple, nous pouvons l'utiliser pour itérer à l'intérieur d'une méthode d'objet:
2424

2525
```js run
2626
let group = {
@@ -39,9 +39,9 @@ let group = {
3939
group.showList();
4040
```
4141

42-
Here in `forEach`, the arrow function is used, so `this.title` in it is exactly the same as in the outer method `showList`. That is: `group.title`.
42+
Ici, dans `forEach`, une fonction une fléchée est utilisée, donc `this.title` est exactement la même chose que dans la méthode externe `showList`. C'est-à-dire `group.title`.
4343

44-
If we used a "regular" function, there would be an error:
44+
Si nous utilisions une fonction "régulière", il y aurait une erreur:
4545

4646
```js run
4747
let group = {
@@ -61,28 +61,28 @@ let group = {
6161
group.showList();
6262
```
6363

64-
The error occurs because `forEach` runs functions with `this=undefined` by default, so the attempt to access `undefined.title` is made.
64+
L'erreur se produit parce que `forEach` exécute des fonctions avec` this = undefined` par défaut. La tentative d'accès à `undefined.title` est donc effectuée.
6565

66-
That doesn't affect arrow functions, because they just don't have `this`.
66+
Cela n’affecte pas les fonctions fléchées, car elles n’ont simplement pas de `this`.
6767

68-
```warn header="Arrow functions can't run with `new`"
69-
Not having `this` naturally means another limitation: arrow functions can't be used as constructors. They can't be called with `new`.
68+
```warn header="Les fonctions fléchées ne peuvent pas fonctionner avec `new`"
69+
Ne pas avoir `this` signifie naturellement une autre limitation: les fonctions fléchées ne peuvent pas être utilisées en tant que constructeurs. Ils ne peuvent pas être appelés avec `new`.
7070
```
7171
72-
```smart header="Arrow functions VS bind"
73-
There's a subtle difference between an arrow function `=>` and a regular function called with `.bind(this)`:
72+
```smart header="Fonctions fléchées VS bind"
73+
Il y a une différence subtile entre une fonction fléchée `=>` et une fonction régulière appelée avec `.bind(this)`:
7474
75-
- `.bind(this)` creates a "bound version" of the function.
76-
- The arrow `=>` doesn't create any binding. The function simply doesn't have `this`. The lookup of `this` is made exactly the same way as a regular variable search: in the outer lexical environment.
75+
- `.bind(this)` crée une "version liée" de la fonction.
76+
- La flèche `=>` ne crée aucune liaison. La fonction n'a tout simplement pas de `this`. La recherche de `this` est faite exactement de la même manière qu’une recherche de variable normale: dans l’environnement lexical externe.
7777
```
7878

79-
## Arrows have no "arguments"
79+
## Les fonctions fléchées n'ont pas de "arguments"
8080

81-
Arrow functions also have no `arguments` variable.
81+
Les fonctions fléchées n'ont pas non plus de variable `arguments`.
8282

83-
That's great for decorators, when we need to forward a call with the current `this` and `arguments`.
83+
C'est très bien pour les décorateurs, quand nous avons besoin de transférer un appel avec le `this` et les `arguments` actuels.
8484

85-
For instance, `defer(f, ms)` gets a function and returns a wrapper around it that delays the call by `ms` milliseconds:
85+
Par exemple, `defer(f, ms)` obtient une fonction et retourne un wrapper qui retarde l'appel de `ms` millisecondes:
8686

8787
```js run
8888
function defer(f, ms) {
@@ -96,10 +96,10 @@ function sayHi(who) {
9696
}
9797

9898
let sayHiDeferred = defer(sayHi, 2000);
99-
sayHiDeferred("John"); // Hello, John after 2 seconds
99+
sayHiDeferred("John"); // Hello, John après 2 secondes
100100
```
101101

102-
The same without an arrow function would look like:
102+
La même chose sans une fonction fléchée ressemblerait à ceci:
103103

104104
```js
105105
function defer(f, ms) {
@@ -112,15 +112,15 @@ function defer(f, ms) {
112112
}
113113
```
114114

115-
Here we had to create additional variables `args` and `ctx` so that the function inside `setTimeout` could take them.
115+
Ici, nous avons dû créer des variables additionnelles `args` et `ctx` afin que la fonction à l'intérieur de `setTimeout` puisse les prendre.
116116

117-
## Summary
117+
## Résumé
118118

119-
Arrow functions:
119+
Les fonctions fléchées:
120120

121-
- Do not have `this`.
122-
- Do not have `arguments`.
123-
- Can't be called with `new`.
124-
- (They also don't have `super`, but we didn't study it. Will be in the chapter <info:class-inheritance>).
121+
- N'ont pas de `this`.
122+
- N'ont pas de `arguments`.
123+
- Ne peuvent pas être appelées avec `new`.
124+
- (Ils n'ont pas non plus "super", mais nous ne l'avons pas encore étudié. Ça sera dans le chapitre <info:class-inheritance>).
125125

126-
That's because they are meant for short pieces of code that do not have their own "context", but rather works in the current one. And they really shine in that use case.
126+
En effet, ils sont destinés à de courts morceaux de code qui ne possèdent pas leur propre "contexte", mais fonctionnent dans le contexte actuel. Et ils brillent vraiment dans ce cas d'utilisation.

0 commit comments

Comments
 (0)