Skip to content

Commit 0f21937

Browse files
committed
Translates Extending built-in classes into French
1 parent 09bce53 commit 0f21937

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
# Extending built-in classes
2+
# Extension des classes intégrées
33

4-
Built-in classes like Array, Map and others are extendable also.
4+
Les classes intégrées telles que Array, Map et autres sont également extensibles.
55

6-
For instance, here `PowerArray` inherits from the native `Array`:
6+
Par exemple, ici, `PowerArray` hérite du `Array` natif:
77

88
```js run
9-
// add one more method to it (can do more)
9+
// ajoutez-y une méthode supplémentaire
1010
class PowerArray extends Array {
1111
isEmpty() {
1212
return this.length === 0;
@@ -21,20 +21,20 @@ alert(filteredArr); // 10, 50
2121
alert(filteredArr.isEmpty()); // false
2222
```
2323

24-
Please note a very interesting thing. Built-in methods like `filter`, `map` and others -- return new objects of exactly the inherited type `PowerArray`. Their internal implementation uses object `constructor` property for that.
24+
Noter une chose très intéressante. Les méthodes intégrées telles que `filter`, `map` et autres renvoient des nouveaux objets exactement du type hérité `PowerArray`. Leur implémentation interne utilise la propriété d'objet `constructor` pour cela.
2525

26-
In the example above,
26+
Dans l'exemple ci-dessus,
2727
```js
2828
arr.constructor === PowerArray
2929
```
3030

31-
When `arr.filter()` is called, it internally creates the new array of results using exactly `arr.constructor`, not basic `Array`. That's actually very cool, because we can keep using `PowerArray` methods further on the result.
31+
Lorsque `arr.filter()` est appelé, elle crée en interne le nouveau tableau de résultats en utilisant exactement `arr.constructor`, et non pas `Array`. C'est en fait très intéressant, car nous pouvons continuer à utiliser les méthodes `PowerArray` sur le résultat.
3232

33-
Even more, we can customize that behavior.
33+
Encore plus, nous pouvons personnaliser ce comportement.
3434

35-
We can add a special static getter `Symbol.species` to the class. If exists, it should return the constructor that JavaScript will use internally to create new entities in `map`, `filter` and so on.
35+
Nous pouvons ajouter un accésseur statique spécial `Symbol.species` à la classe. S'il existe, il devrait renvoyer le constructeur que JavaScript utilisera en interne pour créer de nouvelles entités dans `map`, `filter`, etc.
3636

37-
If we'd like built-in methods like `map` or `filter` to return regular arrays, we can return `Array` in `Symbol.species`, like here:
37+
Si nous souhaitons que des méthodes intégrées comme `map` ou `filter` renvoient des tableaux classiques, nous pouvons retourner `Array` dans `Symbol.species`, comme ici:
3838

3939
```js run
4040
class PowerArray extends Array {
@@ -43,7 +43,7 @@ class PowerArray extends Array {
4343
}
4444

4545
*!*
46-
// built-in methods will use this as the constructor
46+
// les méthodes intégrées l'utiliseront comme constructeur
4747
static get [Symbol.species]() {
4848
return Array;
4949
}
@@ -53,37 +53,37 @@ class PowerArray extends Array {
5353
let arr = new PowerArray(1, 2, 5, 10, 50);
5454
alert(arr.isEmpty()); // false
5555

56-
// filter creates new array using arr.constructor[Symbol.species] as constructor
56+
// filter crée un nouveau tableau en utilisant arr.constructor [Symbol.species] comme constructeur
5757
let filteredArr = arr.filter(item => item >= 10);
5858

5959
*!*
60-
// filteredArr is not PowerArray, but Array
60+
// filteredArr n'est pas PowerArray, mais Array
6161
*/!*
6262
alert(filteredArr.isEmpty()); // Error: filteredArr.isEmpty is not a function
6363
```
6464

65-
As you can see, now `.filter` returns `Array`. So the extended functionality is not passed any further.
65+
Comme vous pouvez le constater, maintenant, `.filter` renvoie `Array`. La fonctionnalité étendue n'est donc plus transmise.
6666

67-
```smart header="Other collections work similarly"
68-
Other collections, such as `Map` and `Set`, work alike. They also use `Symbol.species`.
67+
```smart header="D'autres collections fonctionnent de la même manière"
68+
D'autres collections, telles que `Map` et `Set`, fonctionnent de la même manière. Ils utilisent également `Symbol.species`.
6969
```
7070

71-
## No static inheritance in built-ins
71+
## Pas d'héritage statique dans les éléments intégrés
7272

73-
Built-in objects have their own static methods, for instance `Object.keys`, `Array.isArray` etc.
73+
Les objets intégrés ont leurs propres méthodes statiques, par exemple `Object.keys`,` Array.isArray` etc.
7474

75-
As we already know, native classes extend each other. For instance, `Array` extends `Object`.
75+
Comme nous le savons déjà, les classes natives s'étendent les uns des autres. Par exemple, `Array` extends `Object`.
7676

77-
Normally, when one class extends another, both static and non-static methods are inherited. That was thoroughly explained in the chapter [](info:static-properties-methods#statics-and-inheritance).
77+
Normalement, lorsqu'une classe en étend une autre, les méthodes statiques et non statiques sont héritées. Cela a été expliqué en détail dans le chapitre [](info:static-properties-methods#statics-and-inheritance).
7878

79-
But built-in classes are an exception. They don't inherit statics from each other.
79+
Mais les classes intégrées sont une exception. Ils n'héritent pas les méthodes statiques les uns des autres.
8080

81-
For example, both `Array` and `Date` inherit from `Object`, so their instances have methods from `Object.prototype`. But `Array.[[Prototype]]` does not reference `Object`, so there's no `Array.keys()` and `Date.keys()` static methods.
81+
Par exemple, `Array` et `Date` héritent de `Object`, de sorte que leurs instances ont des méthodes issues de `Object.prototype`. Mais `Array.[[Prototype]]` ne fait pas référence à `Object`, il n'y a donc pas de méthodes statiques `Array.keys()` et `Date.keys()`.
8282

83-
Here's the picture structure for `Date` and `Object`:
83+
Voici la structure d'image pour `Date` et `Object`:
8484

8585
![](object-date-inheritance.svg)
8686

87-
As you can see, there's no link between `Date` and `Object`. They are independent, only `Date.prototype` inherits from `Object.prototype`.
87+
Comme vous pouvez le constater, il n'y a pas de lien entre `Date` et `Object`. Ils sont indépendants, seul `Date.prototype` hérite de `Object.prototype`.
8888

89-
That's an important difference of inheritance between built-in objects compared to what we get with `extends`.
89+
C'est une différence d'héritage importante entre les objets intégrés par rapport à ce que nous obtenons avec `extends`.

0 commit comments

Comments
 (0)