-
Notifications
You must be signed in to change notification settings - Fork 8.1k
/
index.md
55 lines (36 loc) · 1.2 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
title: get Array[@@species]
slug: Web/JavaScript/Reference/Global_Objects/Array/@@species
---
{{JSRef}}
La propriété d'accesseur **`Array[@@species]`** renvoie le constructeur `Array`.
## Syntaxe
```js
Array[Symbol.species];
```
### Valeur de retour
Le constructeur {{jsxref("Array")}}.
## Description
L'accesseur `species` renvoie le constructeur par défaut pour les objets `Array`. Les constructeurs des sous-classes peuvent le surcharger afin de modifier l'affectation du constructeur.
## Exemples
La propriété renvoie le constructeur par défaut, dans le cas des objets `Array`, c'est le constructeur `Array` :
```js
Array[Symbol.species]; // function Array()
```
Pour un objet dérivé, la valeur de `species` pour une classe `MonArray` sera le constructeur de cette classe. Vous pouvez surcharger ce comportement afin de renvoyer le constructeur `Array` :
```js
class MonArray extends Array {
// On surcharge le symbole species
// pour renvoyer le constructeur Array parent
static get [Symbol.species]() {
return Array;
}
}
```
## Spécifications
{{Specifications}}
## Compatibilité des navigateurs
{{Compat}}
## Voir aussi
- {{jsxref("Array")}}
- {{jsxref("Symbol.species")}}