From 844f5103992238c0c23203286dad16a466e89c97 Mon Sep 17 00:00:00 2001 From: julieng Date: Tue, 3 Aug 2021 08:03:09 +0200 Subject: move *.html to *.md --- .../global_objects/symbol/@@toprimitive/index.html | 63 ------ .../global_objects/symbol/@@toprimitive/index.md | 63 ++++++ .../global_objects/symbol/asynciterator/index.html | 79 ------- .../global_objects/symbol/asynciterator/index.md | 79 +++++++ .../global_objects/symbol/description/index.html | 71 ------- .../global_objects/symbol/description/index.md | 71 +++++++ .../reference/global_objects/symbol/for/index.html | 110 ---------- .../reference/global_objects/symbol/for/index.md | 110 ++++++++++ .../global_objects/symbol/hasinstance/index.html | 64 ------ .../global_objects/symbol/hasinstance/index.md | 64 ++++++ .../reference/global_objects/symbol/index.html | 226 --------------------- .../reference/global_objects/symbol/index.md | 226 +++++++++++++++++++++ .../symbol/isconcatspreadable/index.html | 109 ---------- .../symbol/isconcatspreadable/index.md | 109 ++++++++++ .../global_objects/symbol/iterator/index.html | 121 ----------- .../global_objects/symbol/iterator/index.md | 121 +++++++++++ .../global_objects/symbol/keyfor/index.html | 77 ------- .../global_objects/symbol/keyfor/index.md | 77 +++++++ .../global_objects/symbol/match/index.html | 78 ------- .../reference/global_objects/symbol/match/index.md | 78 +++++++ .../global_objects/symbol/matchall/index.html | 64 ------ .../global_objects/symbol/matchall/index.md | 64 ++++++ .../global_objects/symbol/replace/index.html | 58 ------ .../global_objects/symbol/replace/index.md | 58 ++++++ .../global_objects/symbol/search/index.html | 58 ------ .../global_objects/symbol/search/index.md | 58 ++++++ .../global_objects/symbol/species/index.html | 72 ------- .../global_objects/symbol/species/index.md | 72 +++++++ .../global_objects/symbol/split/index.html | 58 ------ .../reference/global_objects/symbol/split/index.md | 58 ++++++ .../global_objects/symbol/toprimitive/index.html | 87 -------- .../global_objects/symbol/toprimitive/index.md | 87 ++++++++ .../global_objects/symbol/tosource/index.html | 59 ------ .../global_objects/symbol/tosource/index.md | 59 ++++++ .../global_objects/symbol/tostring/index.html | 79 ------- .../global_objects/symbol/tostring/index.md | 79 +++++++ .../global_objects/symbol/tostringtag/index.html | 92 --------- .../global_objects/symbol/tostringtag/index.md | 92 +++++++++ .../global_objects/symbol/unscopables/index.html | 92 --------- .../global_objects/symbol/unscopables/index.md | 92 +++++++++ .../global_objects/symbol/valueof/index.html | 63 ------ .../global_objects/symbol/valueof/index.md | 63 ++++++ 42 files changed, 1780 insertions(+), 1780 deletions(-) delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/@@toprimitive/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/@@toprimitive/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/description/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/description/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/for/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/for/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/hasinstance/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/hasinstance/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/isconcatspreadable/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/isconcatspreadable/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/iterator/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/iterator/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/keyfor/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/keyfor/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/match/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/match/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/matchall/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/matchall/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/replace/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/replace/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/search/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/search/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/species/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/species/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/split/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/split/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/toprimitive/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/toprimitive/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/tosource/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/tosource/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/tostring/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/tostring/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/tostringtag/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/tostringtag/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/unscopables/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/unscopables/index.md delete mode 100644 files/fr/web/javascript/reference/global_objects/symbol/valueof/index.html create mode 100644 files/fr/web/javascript/reference/global_objects/symbol/valueof/index.md (limited to 'files/fr/web/javascript/reference/global_objects/symbol') diff --git a/files/fr/web/javascript/reference/global_objects/symbol/@@toprimitive/index.html b/files/fr/web/javascript/reference/global_objects/symbol/@@toprimitive/index.html deleted file mode 100644 index 601aaceead..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/@@toprimitive/index.html +++ /dev/null @@ -1,63 +0,0 @@ ---- -title: Symbol.prototype[@@toPrimitive] -slug: Web/JavaScript/Reference/Global_Objects/Symbol/@@toPrimitive -tags: - - ECMAScript 2015 - - JavaScript - - Méthode - - Prototype - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/@@toPrimitive -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/@@toPrimitive ---- -
{{JSRef}}
- -

La méthode [@@toPrimitive]() permet de convertir un objet symbole en une valeur primitive.

- -

Syntaxe

- -
Symbol()[Symbol.toPrimitive](hint);
-
- -

Valeur de retour

- -

La valeur primitive de l'objet {{jsxref("Symbol")}} indiqué.

- -

Description

- -

La méthode [@@toPrimitive]() de {{jsxref("Symbol")}} renvoie la valeur primitive d'un objet Symbol (le résultat sera  donc un symbole au sens primitif). L'argument hint n'est pas utilisé.

- -

Le moteur JavaScript appelle la méthode [@@toPrimitive]() afin de convertir un objet en une valeur primitive. Généralement, il n'est pas nécessaire d'appeler [@@toPrimitive]() car le moteur JavaScript l'appelle automatiquement lorsqu'il détecte un objet là où une valeur primitive est attendue.

- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.prototype-@@toprimitive', 'Symbol.prototype.@@toPrimitive')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.prototype-@@toprimitive', 'Symbol.prototype.@@toPrimitive')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.@@toPrimitive")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/@@toprimitive/index.md b/files/fr/web/javascript/reference/global_objects/symbol/@@toprimitive/index.md new file mode 100644 index 0000000000..601aaceead --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/@@toprimitive/index.md @@ -0,0 +1,63 @@ +--- +title: Symbol.prototype[@@toPrimitive] +slug: Web/JavaScript/Reference/Global_Objects/Symbol/@@toPrimitive +tags: + - ECMAScript 2015 + - JavaScript + - Méthode + - Prototype + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/@@toPrimitive +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/@@toPrimitive +--- +
{{JSRef}}
+ +

La méthode [@@toPrimitive]() permet de convertir un objet symbole en une valeur primitive.

+ +

Syntaxe

+ +
Symbol()[Symbol.toPrimitive](hint);
+
+ +

Valeur de retour

+ +

La valeur primitive de l'objet {{jsxref("Symbol")}} indiqué.

+ +

Description

+ +

La méthode [@@toPrimitive]() de {{jsxref("Symbol")}} renvoie la valeur primitive d'un objet Symbol (le résultat sera  donc un symbole au sens primitif). L'argument hint n'est pas utilisé.

+ +

Le moteur JavaScript appelle la méthode [@@toPrimitive]() afin de convertir un objet en une valeur primitive. Généralement, il n'est pas nécessaire d'appeler [@@toPrimitive]() car le moteur JavaScript l'appelle automatiquement lorsqu'il détecte un objet là où une valeur primitive est attendue.

+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.prototype-@@toprimitive', 'Symbol.prototype.@@toPrimitive')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.prototype-@@toprimitive', 'Symbol.prototype.@@toPrimitive')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.@@toPrimitive")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.html b/files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.html deleted file mode 100644 index c70f09bb88..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.html +++ /dev/null @@ -1,79 +0,0 @@ ---- -title: Symbol.asyncIterator -slug: Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator -tags: - - ECMAScript 2018 - - JavaScript - - Propriété - - Reference - - Symbole -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/asyncIterator ---- -
{{JSRef}}
- -

Le symbole connu Symbol.asyncIterator définit l'itérateur asynchrone par défaut d'un objet. Si cette propriété est définie sur un objet, celui-ci est un itérable asynchrone et peut être utilisé avec une boucle for await...of.

- -

{{js_property_attributes(0,0,0)}}

- -

Description

- -

Le symbole Symbol.asyncIterator est un symbole natif utilisé pour accéder à la méthode @@asyncIterator d'un objet. Pour qu'un objet soit un itérable asynchrone, il doit avoir une clé Symbol.asyncIterator.

- -

Exemples

- -

Itérable asynchrone personnalisé

- -

Il est possible de définir son propre itérable en définissant la propriété [Symbol.asyncIterator] d'un objet :

- -
const myAsyncIterable = new Object();
-myAsyncIterable[Symbol.asyncIterator] = async function*() {
-    yield "coucou";
-    yield "l'itération";
-    yield "asynchrone !";
-};
-
-(async () => {
-    for await (const x of myAsyncIterable) {
-        console.log(x);
-        // expected output:
-        //    "coucou"
-        //    "l'itération"
-        //    "asynchrone !"
-    }
-})();
-
- -

Itérables asynchrones natifs

- -

Il n'existe actuellement pas d'objets JavaScript natifs qui possèdent la clé [Symbol.asyncIterator] par défaut. Toutefois, les flux (Streams) WHATWG pourraient devenir les premiers objets natifs itérables asynchrones.

- -

Spécifications

- - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2018', '#sec-symbol.asynciterator', 'Symbol.asyncIterator')}}{{Spec2('ES2018')}} 
- -

Compatibilité des navigateurs

- -

{{compat("javascript.builtins.Symbol.asyncIterator")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.md b/files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.md new file mode 100644 index 0000000000..c70f09bb88 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/asynciterator/index.md @@ -0,0 +1,79 @@ +--- +title: Symbol.asyncIterator +slug: Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator +tags: + - ECMAScript 2018 + - JavaScript + - Propriété + - Reference + - Symbole +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/asyncIterator +--- +
{{JSRef}}
+ +

Le symbole connu Symbol.asyncIterator définit l'itérateur asynchrone par défaut d'un objet. Si cette propriété est définie sur un objet, celui-ci est un itérable asynchrone et peut être utilisé avec une boucle for await...of.

+ +

{{js_property_attributes(0,0,0)}}

+ +

Description

+ +

Le symbole Symbol.asyncIterator est un symbole natif utilisé pour accéder à la méthode @@asyncIterator d'un objet. Pour qu'un objet soit un itérable asynchrone, il doit avoir une clé Symbol.asyncIterator.

+ +

Exemples

+ +

Itérable asynchrone personnalisé

+ +

Il est possible de définir son propre itérable en définissant la propriété [Symbol.asyncIterator] d'un objet :

+ +
const myAsyncIterable = new Object();
+myAsyncIterable[Symbol.asyncIterator] = async function*() {
+    yield "coucou";
+    yield "l'itération";
+    yield "asynchrone !";
+};
+
+(async () => {
+    for await (const x of myAsyncIterable) {
+        console.log(x);
+        // expected output:
+        //    "coucou"
+        //    "l'itération"
+        //    "asynchrone !"
+    }
+})();
+
+ +

Itérables asynchrones natifs

+ +

Il n'existe actuellement pas d'objets JavaScript natifs qui possèdent la clé [Symbol.asyncIterator] par défaut. Toutefois, les flux (Streams) WHATWG pourraient devenir les premiers objets natifs itérables asynchrones.

+ +

Spécifications

+ + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2018', '#sec-symbol.asynciterator', 'Symbol.asyncIterator')}}{{Spec2('ES2018')}} 
+ +

Compatibilité des navigateurs

+ +

{{compat("javascript.builtins.Symbol.asyncIterator")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/description/index.html b/files/fr/web/javascript/reference/global_objects/symbol/description/index.html deleted file mode 100644 index c538e5f35f..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/description/index.html +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: Symbol.prototype.description -slug: Web/JavaScript/Reference/Global_Objects/Symbol/description -tags: - - JavaScript - - Propriété - - Prototype - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/description -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/description ---- -
{{JSRef}}
- -

La propriété en lecture seule description est une chaîne de caractères qui renvoie la description optionnelle de l'objet {{jsxref("Symbol")}}.

- -
{{EmbedInteractiveExample("pages/js/symbol-prototype-description.html")}}
- -

Syntaxe

- -
Symbol('maDescription').description;
-Symbol.iterator.description;
-Symbol.for('toto').description;
-
- -

Description

- -

Les objets {{jsxref("Symbol")}} peuvent être créés avec une description facultative qui peut être utilisée pour du débogage mais sans accéder au symbole. La propriété Symbol.prototype.description peut être utilisée afin de lire cette description. Cette propriété est différente de Symbol.prototype.toString() car elle ne contient pas la chaîne de caractères "Symbol()" autour de la description (voir les exemples qui suivent).

- -

Exemples

- -
Symbol('desc').toString();   // "Symbol(desc)"
-Symbol('desc').description;  // "desc"
-Symbol('').description;      // ""
-Symbol().description;        // undefined
-
-// symboles connus
-Symbol.iterator.toString();  // "Symbol(Symbol.iterator)"
-Symbol.iterator.description; // "Symbol.iterator"
-
-// symboles globaux
-Symbol.for('toto').toString();  // "Symbol(toto)"
-Symbol.for('toto').description; // "toto"
-
-
- -

Spécifications

- - - - - - - - - - - - -
SpécificationÉtat
Proposition pour Symbol.prototype.descriptionProposition de niveau 4
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.description")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/description/index.md b/files/fr/web/javascript/reference/global_objects/symbol/description/index.md new file mode 100644 index 0000000000..c538e5f35f --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/description/index.md @@ -0,0 +1,71 @@ +--- +title: Symbol.prototype.description +slug: Web/JavaScript/Reference/Global_Objects/Symbol/description +tags: + - JavaScript + - Propriété + - Prototype + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/description +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/description +--- +
{{JSRef}}
+ +

La propriété en lecture seule description est une chaîne de caractères qui renvoie la description optionnelle de l'objet {{jsxref("Symbol")}}.

+ +
{{EmbedInteractiveExample("pages/js/symbol-prototype-description.html")}}
+ +

Syntaxe

+ +
Symbol('maDescription').description;
+Symbol.iterator.description;
+Symbol.for('toto').description;
+
+ +

Description

+ +

Les objets {{jsxref("Symbol")}} peuvent être créés avec une description facultative qui peut être utilisée pour du débogage mais sans accéder au symbole. La propriété Symbol.prototype.description peut être utilisée afin de lire cette description. Cette propriété est différente de Symbol.prototype.toString() car elle ne contient pas la chaîne de caractères "Symbol()" autour de la description (voir les exemples qui suivent).

+ +

Exemples

+ +
Symbol('desc').toString();   // "Symbol(desc)"
+Symbol('desc').description;  // "desc"
+Symbol('').description;      // ""
+Symbol().description;        // undefined
+
+// symboles connus
+Symbol.iterator.toString();  // "Symbol(Symbol.iterator)"
+Symbol.iterator.description; // "Symbol.iterator"
+
+// symboles globaux
+Symbol.for('toto').toString();  // "Symbol(toto)"
+Symbol.for('toto').description; // "toto"
+
+
+ +

Spécifications

+ + + + + + + + + + + + +
SpécificationÉtat
Proposition pour Symbol.prototype.descriptionProposition de niveau 4
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.description")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/for/index.html b/files/fr/web/javascript/reference/global_objects/symbol/for/index.html deleted file mode 100644 index 06bb734b9f..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/for/index.html +++ /dev/null @@ -1,110 +0,0 @@ ---- -title: Symbol.for() -slug: Web/JavaScript/Reference/Global_Objects/Symbol/for -tags: - - ECMAScript 2015 - - JavaScript - - Méthode - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/for -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/for ---- -
{{JSRef}}
- -

La méthode Symbol.for(clé) permet de chercher parmi les symboles existants enregistrés dans le registre global de l'environnement d'exécution. Si un symbole associé à la clé donnée existe, il est renvoyé par la fonction, sinon un nouveau symbole associé à cette clé est créé dans le registre.

- -
{{EmbedInteractiveExample("pages/js/symbol-for.html")}}
- -

Syntaxe

- -
Symbol.for(clé);
- -

Paramètres

- -
-
clé
-
Une chaîne de caractères, obligatoire. La clé correspondant au symbole (également utilisée pour la description du symbole).
-
- -

Valeur de retour

- -

Un symbole existant s'il en a été trouvé un avec la clé fournie. Sinon, un nouveau symbole est créé puis renvoyé par la méthode.

- -

Description

- -

À la différence de Symbol(), la méthode Symbol.for() crée un symbole enregistré dans le registre global. Symbol.for() ne crée pas nécessairement un nouveau symbole pour chaque appel, elle vérifie d'abord si un symbole avec la clé donnée est d'ores et déjà présent dans le registre. Si c'est le cas, le symbole correspondant est renvoyé, sinon Symbol.for() crée un nouveau symbol global.

- -

Registre global pour les symboles

- -

Le registre global des symboles est une liste, initialement vide, dont les éléments ont la structure suivante :

- - - - - - - - - - - - - - - - - -
Structure d'un enregistrement dans le registre global des symboles
Nom du champValeur
[[key]]Une chaîne de caractères représentant la clé pour identifier un symbole en particulier.
[[symbol]]Un symbole enregistré de façon globale.
- -

Exemples

- -
Symbol.for("toto"); // crée un nouveau symbole global
-Symbol.for("toto"); // renvoie le symbole déjà existant
-
-// Globalement on a un symbole par clé, localement non
-Symbol.for("machin") === Symbol.for("machin"); // true
-Symbol("machin") === Symbol("machin"); // false
-
-// La clé sert également de description
-var sym = Symbol.for("mario");
-sym.toString(); // "Symbol(mario)"
-
- -

Afin d'éviter des conflits entre les clés des symboles globaux liés à votre application et les autres symboles potentiels (bibliothèques externes, etc...), il peut être judicieux de les préfixer :

- -
Symbol.for("mdn.toto");
-Symbol.for("mdn.machin");
-
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.for', 'Symbol.for')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.for', 'Symbol.for')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.for")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/for/index.md b/files/fr/web/javascript/reference/global_objects/symbol/for/index.md new file mode 100644 index 0000000000..06bb734b9f --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/for/index.md @@ -0,0 +1,110 @@ +--- +title: Symbol.for() +slug: Web/JavaScript/Reference/Global_Objects/Symbol/for +tags: + - ECMAScript 2015 + - JavaScript + - Méthode + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/for +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/for +--- +
{{JSRef}}
+ +

La méthode Symbol.for(clé) permet de chercher parmi les symboles existants enregistrés dans le registre global de l'environnement d'exécution. Si un symbole associé à la clé donnée existe, il est renvoyé par la fonction, sinon un nouveau symbole associé à cette clé est créé dans le registre.

+ +
{{EmbedInteractiveExample("pages/js/symbol-for.html")}}
+ +

Syntaxe

+ +
Symbol.for(clé);
+ +

Paramètres

+ +
+
clé
+
Une chaîne de caractères, obligatoire. La clé correspondant au symbole (également utilisée pour la description du symbole).
+
+ +

Valeur de retour

+ +

Un symbole existant s'il en a été trouvé un avec la clé fournie. Sinon, un nouveau symbole est créé puis renvoyé par la méthode.

+ +

Description

+ +

À la différence de Symbol(), la méthode Symbol.for() crée un symbole enregistré dans le registre global. Symbol.for() ne crée pas nécessairement un nouveau symbole pour chaque appel, elle vérifie d'abord si un symbole avec la clé donnée est d'ores et déjà présent dans le registre. Si c'est le cas, le symbole correspondant est renvoyé, sinon Symbol.for() crée un nouveau symbol global.

+ +

Registre global pour les symboles

+ +

Le registre global des symboles est une liste, initialement vide, dont les éléments ont la structure suivante :

+ + + + + + + + + + + + + + + + + +
Structure d'un enregistrement dans le registre global des symboles
Nom du champValeur
[[key]]Une chaîne de caractères représentant la clé pour identifier un symbole en particulier.
[[symbol]]Un symbole enregistré de façon globale.
+ +

Exemples

+ +
Symbol.for("toto"); // crée un nouveau symbole global
+Symbol.for("toto"); // renvoie le symbole déjà existant
+
+// Globalement on a un symbole par clé, localement non
+Symbol.for("machin") === Symbol.for("machin"); // true
+Symbol("machin") === Symbol("machin"); // false
+
+// La clé sert également de description
+var sym = Symbol.for("mario");
+sym.toString(); // "Symbol(mario)"
+
+ +

Afin d'éviter des conflits entre les clés des symboles globaux liés à votre application et les autres symboles potentiels (bibliothèques externes, etc...), il peut être judicieux de les préfixer :

+ +
Symbol.for("mdn.toto");
+Symbol.for("mdn.machin");
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.for', 'Symbol.for')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.for', 'Symbol.for')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.for")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/hasinstance/index.html b/files/fr/web/javascript/reference/global_objects/symbol/hasinstance/index.html deleted file mode 100644 index 4809e68bcc..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/hasinstance/index.html +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: Symbol.hasInstance -slug: Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance -tags: - - ECMAScript 2015 - - JavaScript - - Propriété - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/hasInstance ---- -
{{JSRef}}
- -

Le symbole « connu » Symbol.hasInstance est utilisé afin de déterminer si un objet constructeur reconnaît un objet comme une de ses instances. On peut donc adapter/personnaliser le comportement de l'opérateur {{jsxref("Opérateurs/instanceof", "instanceof")}} grâce à ce symbole.

- -
{{EmbedInteractiveExample("pages/js/symbol-hasinstance.html")}}
- - - -
{{js_property_attributes(0,0,0)}}
- -

Exemples

- -

On peut implémenter un comportement différent pour instanceof de cette façon :

- -
class MonArray {
-  static [Symbol.hasInstance](instance) {
-    return Array.isArray(instance);
-  }
-}
-console.log([] instanceof MonArray); // true
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.hasinstance', 'Symbol.hasInstance')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.hasinstance', 'Symbol.hasInstance')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.hasInstance")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/hasinstance/index.md b/files/fr/web/javascript/reference/global_objects/symbol/hasinstance/index.md new file mode 100644 index 0000000000..4809e68bcc --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/hasinstance/index.md @@ -0,0 +1,64 @@ +--- +title: Symbol.hasInstance +slug: Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance +tags: + - ECMAScript 2015 + - JavaScript + - Propriété + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/hasInstance +--- +
{{JSRef}}
+ +

Le symbole « connu » Symbol.hasInstance est utilisé afin de déterminer si un objet constructeur reconnaît un objet comme une de ses instances. On peut donc adapter/personnaliser le comportement de l'opérateur {{jsxref("Opérateurs/instanceof", "instanceof")}} grâce à ce symbole.

+ +
{{EmbedInteractiveExample("pages/js/symbol-hasinstance.html")}}
+ + + +
{{js_property_attributes(0,0,0)}}
+ +

Exemples

+ +

On peut implémenter un comportement différent pour instanceof de cette façon :

+ +
class MonArray {
+  static [Symbol.hasInstance](instance) {
+    return Array.isArray(instance);
+  }
+}
+console.log([] instanceof MonArray); // true
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.hasinstance', 'Symbol.hasInstance')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.hasinstance', 'Symbol.hasInstance')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.hasInstance")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/index.html b/files/fr/web/javascript/reference/global_objects/symbol/index.html deleted file mode 100644 index fdeffa85f1..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/index.html +++ /dev/null @@ -1,226 +0,0 @@ ---- -title: Symbol -slug: Web/JavaScript/Reference/Global_Objects/Symbol -tags: - - ECMAScript 2015 - - JavaScript - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol ---- -
{{JSRef}}
- -

Un symbole est un type de données primitif représentant une donnée unique et inchangeable qui peut être utilisée afin de représenter des identifiants pour des propriétés d'un objet. L'objet Symbol est un conteneur objet implicite pour le {{Glossary("Primitive", "type de données primitif")}} symbole.

- -
{{EmbedInteractiveExample("pages/js/symbol-constructor.html")}}
- -

Syntaxe

- -
Symbol([description])
- -

Paramètres

- -
-
description {{optional_inline}}
-
Une chaîne de caractères optionnelle. Correspond à une description du symbole, elle peut être utile pour déboguer (mais pas pour accéder au symbole).
-
- -

Description

- -

Pour créer un nouveau symbole, il suffit d'appeler Symbol(), éventuellement avec une chaîne de caractère descriptive :

- -
var sym1 = Symbol();
-var sym2 = Symbol("toto");
-var sym3 = Symbol("toto");
-
- -

Le fragment de code ci-dessus permet de créer trois nouveaux symboles. On notera que l'instruction Symbol("toto") ne convertit pas la chaîne "toto" en un symbole. On crée bien un nouveau symbole pour chaque instruction ci-avant.

- -
Symbol("toto") === Symbol("toto"); // false
- -

La syntaxe suivante, utilisant l'opérateur {{jsxref("Opérateurs/L_opérateur_new", "new")}}, entraînera une exception {{jsxref("TypeError")}}:

- -
var sym = new Symbol(); // TypeError
- -

Cela est fait pour empêcher d'écrire un conteneur (wrapper) explicite de Symbol plutôt qu'une nouvelle valeur, cela peut être surprenant car généralement, on peut créer des objets « autour » de types primitifs (par exemple avec new Boolean, new String et new Number).

- -

Si on souhaite obtenir un object contenant un symbole, on pourra toujours utiliser la fonction Object() :

- -
var sym = Symbol("toto");
-typeof sym;     // "symbol"
-var symObj = Object(sym);
-typeof symObj;  // "object"
- -

Symboles partagés et registre global des symboles

- -

La syntaxe manipulée ci-avant, utilisant la fonction Symbol(), ne crée pas un symbole global, disponible partout dans votre code. Pour créer des symboles qui soient disponibles pour différents fichiers et appartiennent à l'environnement global, il faut utiliser les méthodes {{jsxref("Symbol.for()")}} et {{jsxref("Symbol.keyFor()")}} afin de définir et de récupérer les symboles listés dans le registre global.

- -

Trouver les propriétés identifiées par des symboles pour un objet

- -

La méthode {{jsxref("Object.getOwnPropertySymbols()")}} renvoie un tableau de symboles, permettant ainsi de connaître les propriétés identifiées par un symbole pour un objet donné. À l'initialisation, un objet ne contient aucune propriété propre identifiée par un symbole, ce tableau sera donc vide jusqu'à ce qu'une propriété, identifiée par un symbole, lui soit ajoutée.

- -

Les symboles et les conversions

- -

Lorsqu'on utilise des mécanismes de conversion de types avec les symboles, on aura le comportement suivant :

- - - -

Propriétés

- -
-
Symbol.length
-
La propriété length dont la valeur est 0.
-
{{jsxref("Symbol.prototype")}}
-
Cette propriété représente le prototype du constructeur Symbol.
-
- -

Symboles connus

- -

En plus des symboles que vous pouvez créer, JavaScript possède certains symboles natifs représentant des aspects internes du langages qui, pour ECMAScript 5 et les versions précédentes, n'étaient pas exposées aux développeurs. Il est possible d'accéder à ces symboles en utilisant les propriétés suivantes :

- -

Symboles d'itération

- -
-
{{jsxref("Symbol.iterator")}}
-
Une méthode qui renvoie l'itérateur par défaut d'un objet. Ce symbole est utilisé par la boucle {{jsxref("Instructions/for...of","for...of")}}.
-
{{jsxref("Symbol.asyncIterator")}}
-
Une méthode qui renvoie l'itérateur asynchrone par défaut d'un objet. Ce symbole est utilisé par la boucle for await...of.
-
- -

Symboles liés aux expressions rationnelles

- -
-
{{jsxref("Symbol.match")}}
-
Une méthode qui fait correspondre une expression rationnelle avec une chaîne de caractères. Elle est aussi utilisée pour déterminer si un objet peut être utilisé comme une expression rationnelle.
-
{{jsxref("Symbol.matchAll")}}
-
Une méthode qui renvoie un itérateur permettant de parcourir l'ensemble des correspondances entre une chaîne de caractères et une expression rationnelle. Ce symbole est utilisé par {{jsxref("String.prototype.matchAll()")}}.
-
{{jsxref("Symbol.replace")}}
-
Une méthode qui remplace les sous-chaînes correspondantes dans une chaîne de caractères. Utilisée par {{jsxref("String.prototype.replace()")}}.
-
{{jsxref("Symbol.search")}}
-
Une méthode qui renvoie l'indice d'une chaîne de caractères pour lequel on a une correspondance avec une expression rationnelle. Utilisée par {{jsxref("String.prototype.search()")}}.
-
{{jsxref("Symbol.split")}}
-
Une méthode qui découpe la chaîne à l'indice donné par la correspondance avec une expression rationnelle. Utilisée par {{jsxref("String.prototype.split()")}}.
-
- -

Autres symboles

- -
-
{{jsxref("Symbol.hasInstance")}}
-
Une méthode qui permet de déterminer si un constructeur reconnaît un objet comme son instance. Utilisé par {{jsxref("Opérateurs/instanceof", "instanceof")}}.
-
{{jsxref("Symbol.isConcatSpreadable")}}
-
Une valeur booléenne qui indique si un objet devrait être réduit à la concaténation des éléments de son tableau via  {{jsxref("Array.prototype.concat()")}}.
-
{{jsxref("Symbol.unscopables")}}
-
Un objet dont les noms des propriétés propres et héritées sont exclues de l'objet associé lors de l'utilisation de with.
-
{{jsxref("Symbol.species")}}
-
Un constructeur utilisé pour construire des objets dérivés.
-
{{jsxref("Symbol.toPrimitive")}}
-
Spécifié comme @@toPrimitive. Une méthode qui convertit un objet en sa valeur primitive.
-
{{jsxref("Symbol.toStringTag")}}
-
Spécifié comme @@toStringTag. Une chaîne de caractères utilisée pour la description d'un objet. Ce symbole est utilisé par {{jsxref("Object.prototype.toString()")}}.
-
- -

Méthodes

- -
-
{{jsxref("Symbol.for()", "Symbol.for(key)")}}
-
Recherche parmi les symboles existants un symbole désigné par cette clé. S'il est trouvé, le symbole est renvoyé, sinon un nouveau symbole est créé et enregistré avec cette clé dans le registre global des symboles.
-
{{jsxref("Symbol.keyFor", "Symbol.keyFor(sym)")}}
-
Pour un symbole donné, récupère la clé d'un symbole partagé depuis le registre global.
-
- -

Prototype Symbol

- -

Tous les symboles héritent de {{jsxref("Symbol.prototype")}}.

- -

Propriétés

- -

{{page('fr/docs/Web/JavaScript/Reference/Objets_globaux/Symbol/prototype','Propri.C3.A9t.C3.A9s')}}

- -

Méthodes

- -

{{page('fr/docs/Web/JavaScript/Reference/Objets_globaux/Symbol/prototype','M.C3.A9thodes')}}

- -

Exemples

- -

Utiliser l'opérateur typeof avec des symboles

- -

L'opérateur {{jsxref("Opérateurs/L_opérateur_typeof", "typeof")}} permet d'identifier des symboles :

- -
typeof Symbol() === 'symbol'
-typeof Symbol('toto') === 'symbol'
-typeof Symbol.iterator === 'symbol'
-
- -

Les symboles et les boucles for...in

- -

Les symboles ne peuvent pas être énumérés dans les boucles for...in. De plus, la méthode {{jsxref("Object.getOwnPropertyNames()")}} ne renverra pas les propriétés identifiées par des symboles. La méthode {{jsxref("Object.getOwnPropertySymbols()")}} permet d'avoir accès à ces propriétés.

- -
var obj = {};
-
-obj[Symbol("a")] = "a";
-obj[Symbol.for("b")] = "b";
-obj["c"] = "c";
-obj.d = "d";
-
-for (var i in obj) {
-   console.log(i); // enregistre "c" et "d"
-}
- -

Les symboles et JSON.stringify()

- -

Les propriétés identifiées par des symboles seront totalement ignorées par JSON.stringify():

- -
JSON.stringify({[Symbol("toto")]: "toto"});
-// '{}'
- -

Pour plus de détails, voir la page {{jsxref("JSON.stringify()")}}.

- -

Utiliser les symboles enveloppés dans un objet

- -

Lors qu'on on utilise un objet pour contenir la valeur du symbole et faire référence à une propriété, l'objet sera ramené au symbole d'origine :

- -
var sym = Symbol("toto")
-var obj = {[sym]: 1};
-obj[sym];              // 1
-obj[Object(sym)];      // toujours 1
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol-objects', 'Symbol')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol-objects', 'Symbol')}}{{Spec2('ESDraft')}}
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/index.md b/files/fr/web/javascript/reference/global_objects/symbol/index.md new file mode 100644 index 0000000000..fdeffa85f1 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/index.md @@ -0,0 +1,226 @@ +--- +title: Symbol +slug: Web/JavaScript/Reference/Global_Objects/Symbol +tags: + - ECMAScript 2015 + - JavaScript + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol +--- +
{{JSRef}}
+ +

Un symbole est un type de données primitif représentant une donnée unique et inchangeable qui peut être utilisée afin de représenter des identifiants pour des propriétés d'un objet. L'objet Symbol est un conteneur objet implicite pour le {{Glossary("Primitive", "type de données primitif")}} symbole.

+ +
{{EmbedInteractiveExample("pages/js/symbol-constructor.html")}}
+ +

Syntaxe

+ +
Symbol([description])
+ +

Paramètres

+ +
+
description {{optional_inline}}
+
Une chaîne de caractères optionnelle. Correspond à une description du symbole, elle peut être utile pour déboguer (mais pas pour accéder au symbole).
+
+ +

Description

+ +

Pour créer un nouveau symbole, il suffit d'appeler Symbol(), éventuellement avec une chaîne de caractère descriptive :

+ +
var sym1 = Symbol();
+var sym2 = Symbol("toto");
+var sym3 = Symbol("toto");
+
+ +

Le fragment de code ci-dessus permet de créer trois nouveaux symboles. On notera que l'instruction Symbol("toto") ne convertit pas la chaîne "toto" en un symbole. On crée bien un nouveau symbole pour chaque instruction ci-avant.

+ +
Symbol("toto") === Symbol("toto"); // false
+ +

La syntaxe suivante, utilisant l'opérateur {{jsxref("Opérateurs/L_opérateur_new", "new")}}, entraînera une exception {{jsxref("TypeError")}}:

+ +
var sym = new Symbol(); // TypeError
+ +

Cela est fait pour empêcher d'écrire un conteneur (wrapper) explicite de Symbol plutôt qu'une nouvelle valeur, cela peut être surprenant car généralement, on peut créer des objets « autour » de types primitifs (par exemple avec new Boolean, new String et new Number).

+ +

Si on souhaite obtenir un object contenant un symbole, on pourra toujours utiliser la fonction Object() :

+ +
var sym = Symbol("toto");
+typeof sym;     // "symbol"
+var symObj = Object(sym);
+typeof symObj;  // "object"
+ +

Symboles partagés et registre global des symboles

+ +

La syntaxe manipulée ci-avant, utilisant la fonction Symbol(), ne crée pas un symbole global, disponible partout dans votre code. Pour créer des symboles qui soient disponibles pour différents fichiers et appartiennent à l'environnement global, il faut utiliser les méthodes {{jsxref("Symbol.for()")}} et {{jsxref("Symbol.keyFor()")}} afin de définir et de récupérer les symboles listés dans le registre global.

+ +

Trouver les propriétés identifiées par des symboles pour un objet

+ +

La méthode {{jsxref("Object.getOwnPropertySymbols()")}} renvoie un tableau de symboles, permettant ainsi de connaître les propriétés identifiées par un symbole pour un objet donné. À l'initialisation, un objet ne contient aucune propriété propre identifiée par un symbole, ce tableau sera donc vide jusqu'à ce qu'une propriété, identifiée par un symbole, lui soit ajoutée.

+ +

Les symboles et les conversions

+ +

Lorsqu'on utilise des mécanismes de conversion de types avec les symboles, on aura le comportement suivant :

+ + + +

Propriétés

+ +
+
Symbol.length
+
La propriété length dont la valeur est 0.
+
{{jsxref("Symbol.prototype")}}
+
Cette propriété représente le prototype du constructeur Symbol.
+
+ +

Symboles connus

+ +

En plus des symboles que vous pouvez créer, JavaScript possède certains symboles natifs représentant des aspects internes du langages qui, pour ECMAScript 5 et les versions précédentes, n'étaient pas exposées aux développeurs. Il est possible d'accéder à ces symboles en utilisant les propriétés suivantes :

+ +

Symboles d'itération

+ +
+
{{jsxref("Symbol.iterator")}}
+
Une méthode qui renvoie l'itérateur par défaut d'un objet. Ce symbole est utilisé par la boucle {{jsxref("Instructions/for...of","for...of")}}.
+
{{jsxref("Symbol.asyncIterator")}}
+
Une méthode qui renvoie l'itérateur asynchrone par défaut d'un objet. Ce symbole est utilisé par la boucle for await...of.
+
+ +

Symboles liés aux expressions rationnelles

+ +
+
{{jsxref("Symbol.match")}}
+
Une méthode qui fait correspondre une expression rationnelle avec une chaîne de caractères. Elle est aussi utilisée pour déterminer si un objet peut être utilisé comme une expression rationnelle.
+
{{jsxref("Symbol.matchAll")}}
+
Une méthode qui renvoie un itérateur permettant de parcourir l'ensemble des correspondances entre une chaîne de caractères et une expression rationnelle. Ce symbole est utilisé par {{jsxref("String.prototype.matchAll()")}}.
+
{{jsxref("Symbol.replace")}}
+
Une méthode qui remplace les sous-chaînes correspondantes dans une chaîne de caractères. Utilisée par {{jsxref("String.prototype.replace()")}}.
+
{{jsxref("Symbol.search")}}
+
Une méthode qui renvoie l'indice d'une chaîne de caractères pour lequel on a une correspondance avec une expression rationnelle. Utilisée par {{jsxref("String.prototype.search()")}}.
+
{{jsxref("Symbol.split")}}
+
Une méthode qui découpe la chaîne à l'indice donné par la correspondance avec une expression rationnelle. Utilisée par {{jsxref("String.prototype.split()")}}.
+
+ +

Autres symboles

+ +
+
{{jsxref("Symbol.hasInstance")}}
+
Une méthode qui permet de déterminer si un constructeur reconnaît un objet comme son instance. Utilisé par {{jsxref("Opérateurs/instanceof", "instanceof")}}.
+
{{jsxref("Symbol.isConcatSpreadable")}}
+
Une valeur booléenne qui indique si un objet devrait être réduit à la concaténation des éléments de son tableau via  {{jsxref("Array.prototype.concat()")}}.
+
{{jsxref("Symbol.unscopables")}}
+
Un objet dont les noms des propriétés propres et héritées sont exclues de l'objet associé lors de l'utilisation de with.
+
{{jsxref("Symbol.species")}}
+
Un constructeur utilisé pour construire des objets dérivés.
+
{{jsxref("Symbol.toPrimitive")}}
+
Spécifié comme @@toPrimitive. Une méthode qui convertit un objet en sa valeur primitive.
+
{{jsxref("Symbol.toStringTag")}}
+
Spécifié comme @@toStringTag. Une chaîne de caractères utilisée pour la description d'un objet. Ce symbole est utilisé par {{jsxref("Object.prototype.toString()")}}.
+
+ +

Méthodes

+ +
+
{{jsxref("Symbol.for()", "Symbol.for(key)")}}
+
Recherche parmi les symboles existants un symbole désigné par cette clé. S'il est trouvé, le symbole est renvoyé, sinon un nouveau symbole est créé et enregistré avec cette clé dans le registre global des symboles.
+
{{jsxref("Symbol.keyFor", "Symbol.keyFor(sym)")}}
+
Pour un symbole donné, récupère la clé d'un symbole partagé depuis le registre global.
+
+ +

Prototype Symbol

+ +

Tous les symboles héritent de {{jsxref("Symbol.prototype")}}.

+ +

Propriétés

+ +

{{page('fr/docs/Web/JavaScript/Reference/Objets_globaux/Symbol/prototype','Propri.C3.A9t.C3.A9s')}}

+ +

Méthodes

+ +

{{page('fr/docs/Web/JavaScript/Reference/Objets_globaux/Symbol/prototype','M.C3.A9thodes')}}

+ +

Exemples

+ +

Utiliser l'opérateur typeof avec des symboles

+ +

L'opérateur {{jsxref("Opérateurs/L_opérateur_typeof", "typeof")}} permet d'identifier des symboles :

+ +
typeof Symbol() === 'symbol'
+typeof Symbol('toto') === 'symbol'
+typeof Symbol.iterator === 'symbol'
+
+ +

Les symboles et les boucles for...in

+ +

Les symboles ne peuvent pas être énumérés dans les boucles for...in. De plus, la méthode {{jsxref("Object.getOwnPropertyNames()")}} ne renverra pas les propriétés identifiées par des symboles. La méthode {{jsxref("Object.getOwnPropertySymbols()")}} permet d'avoir accès à ces propriétés.

+ +
var obj = {};
+
+obj[Symbol("a")] = "a";
+obj[Symbol.for("b")] = "b";
+obj["c"] = "c";
+obj.d = "d";
+
+for (var i in obj) {
+   console.log(i); // enregistre "c" et "d"
+}
+ +

Les symboles et JSON.stringify()

+ +

Les propriétés identifiées par des symboles seront totalement ignorées par JSON.stringify():

+ +
JSON.stringify({[Symbol("toto")]: "toto"});
+// '{}'
+ +

Pour plus de détails, voir la page {{jsxref("JSON.stringify()")}}.

+ +

Utiliser les symboles enveloppés dans un objet

+ +

Lors qu'on on utilise un objet pour contenir la valeur du symbole et faire référence à une propriété, l'objet sera ramené au symbole d'origine :

+ +
var sym = Symbol("toto")
+var obj = {[sym]: 1};
+obj[sym];              // 1
+obj[Object(sym)];      // toujours 1
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol-objects', 'Symbol')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol-objects', 'Symbol')}}{{Spec2('ESDraft')}}
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/isconcatspreadable/index.html b/files/fr/web/javascript/reference/global_objects/symbol/isconcatspreadable/index.html deleted file mode 100644 index 4d106382a2..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/isconcatspreadable/index.html +++ /dev/null @@ -1,109 +0,0 @@ ---- -title: Symbol.isConcatSpreadable -slug: Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable -tags: - - ECMAScript 2015 - - JavaScript - - Propriété - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/isConcatSpreadable ---- -
{{JSRef}}
- -

Le symbole connu Symbol.isConcatSpreadable est utilisé pour configurer la façon dont un tableau est aplati lors d'une concaténation via la méthode  {{jsxref("Array.prototype.concat()")}}.

- -
{{EmbedInteractiveExample("pages/js/symbol-isconcatspreadable.html")}}
- - - -

Description

- -

Le symbole @@isConcatSpreadable (Symbol.isConcatSpreadable) peut être défini comme une propriété propre ou héritée. C'est une valeur booléenne qui contrôle le comportement des tableaux et des objets semblables à des tableaux :

- - - -

{{js_property_attributes(0,0,0)}}

- -

Exemples

- -

Tableaux (Array)

- -

Par défaut, {{jsxref("Array.prototype.concat()")}} aplatit les tableaux pour le résultat de la concaténation :

- -
var alpha = ['a', 'b', 'c'],
-    numérique = [1, 2, 3];
-
-var alphaNumérique = alpha.concat(numérique);
-
-console.log(alphaNumérique);
-// Résultat : ['a', 'b', 'c', 1, 2, 3]
-
- -

En définissant Symbol.isConcatSpreadable avec false, on peut désactiver le comportement par défaut :

- -
var alpha = ['a', 'b', 'c'],
-    numérique = [1, 2, 3];
-
-numérique[Symbol.isConcatSpreadable] = false;
-var alphaNumérique = alpha.concat(numérique);
-
-console.log(alphaNumérique);
-// Résultat: ['a', 'b', 'c', [1, 2, 3] ]
-
- -

Objets semblables à des tableaux

- -

Pour les objets semblables à un tableau, par défaut, il n'y a pas de fusion. Il faut donc que Symbol.isConcatSpreadable vaille true pour aplatir le tableau :

- -
var x = [1, 2, 3];
-
-var fauxTableau = {
-  [Symbol.isConcatSpreadable]: true,
-  length: 2,
-  0: "coucou",
-  1: "monde"
-}
-
-x.concat(fauxTableau); // [1, 2, 3, "coucou", "monde"]
-
- -
-

Note : La propriété length indique ici le nombre de propriétés à ajouter au tableau.

-
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.isconcatspreadable', 'Symbol.isconcatspreadable')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.isconcatspreadable', 'Symbol.isconcatspreadable')}}{{Spec2('ESDraft')}}Aucune modification.
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.isConcatSpreadable")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/isconcatspreadable/index.md b/files/fr/web/javascript/reference/global_objects/symbol/isconcatspreadable/index.md new file mode 100644 index 0000000000..4d106382a2 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/isconcatspreadable/index.md @@ -0,0 +1,109 @@ +--- +title: Symbol.isConcatSpreadable +slug: Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable +tags: + - ECMAScript 2015 + - JavaScript + - Propriété + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/isConcatSpreadable +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/isConcatSpreadable +--- +
{{JSRef}}
+ +

Le symbole connu Symbol.isConcatSpreadable est utilisé pour configurer la façon dont un tableau est aplati lors d'une concaténation via la méthode  {{jsxref("Array.prototype.concat()")}}.

+ +
{{EmbedInteractiveExample("pages/js/symbol-isconcatspreadable.html")}}
+ + + +

Description

+ +

Le symbole @@isConcatSpreadable (Symbol.isConcatSpreadable) peut être défini comme une propriété propre ou héritée. C'est une valeur booléenne qui contrôle le comportement des tableaux et des objets semblables à des tableaux :

+ + + +

{{js_property_attributes(0,0,0)}}

+ +

Exemples

+ +

Tableaux (Array)

+ +

Par défaut, {{jsxref("Array.prototype.concat()")}} aplatit les tableaux pour le résultat de la concaténation :

+ +
var alpha = ['a', 'b', 'c'],
+    numérique = [1, 2, 3];
+
+var alphaNumérique = alpha.concat(numérique);
+
+console.log(alphaNumérique);
+// Résultat : ['a', 'b', 'c', 1, 2, 3]
+
+ +

En définissant Symbol.isConcatSpreadable avec false, on peut désactiver le comportement par défaut :

+ +
var alpha = ['a', 'b', 'c'],
+    numérique = [1, 2, 3];
+
+numérique[Symbol.isConcatSpreadable] = false;
+var alphaNumérique = alpha.concat(numérique);
+
+console.log(alphaNumérique);
+// Résultat: ['a', 'b', 'c', [1, 2, 3] ]
+
+ +

Objets semblables à des tableaux

+ +

Pour les objets semblables à un tableau, par défaut, il n'y a pas de fusion. Il faut donc que Symbol.isConcatSpreadable vaille true pour aplatir le tableau :

+ +
var x = [1, 2, 3];
+
+var fauxTableau = {
+  [Symbol.isConcatSpreadable]: true,
+  length: 2,
+  0: "coucou",
+  1: "monde"
+}
+
+x.concat(fauxTableau); // [1, 2, 3, "coucou", "monde"]
+
+ +
+

Note : La propriété length indique ici le nombre de propriétés à ajouter au tableau.

+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.isconcatspreadable', 'Symbol.isconcatspreadable')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.isconcatspreadable', 'Symbol.isconcatspreadable')}}{{Spec2('ESDraft')}}Aucune modification.
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.isConcatSpreadable")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/iterator/index.html b/files/fr/web/javascript/reference/global_objects/symbol/iterator/index.html deleted file mode 100644 index 2b3d9bf367..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/iterator/index.html +++ /dev/null @@ -1,121 +0,0 @@ ---- -title: Symbol.iterator -slug: Web/JavaScript/Reference/Global_Objects/Symbol/iterator -tags: - - ECMAScript 2015 - - JavaScript - - Propriété - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/iterator -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/iterator ---- -
{{JSRef}}
- -

Le symbole Symbol.iterator définit l'itérateur par défaut d'un objet. C'est l'itérateur qui sera utilisé par for...of.

- -
{{EmbedInteractiveExample("pages/js/symbol-iterator.html")}}
- - - -

Description

- -

Lorsqu'on doit itérer sur un objet (par exemple avec une boucle for..of), sa méthode @@iterator est appelée sans argument et l'itérateur renvoyé par la méthode est utilisé pour récupérer les valeurs sur lesquelles itérer.

- -

Certains types natifs possèdent un comportement par défaut pour l'itération, d'autres types (tels qu'{{jsxref("Object")}}) n'ont pas de tel comportement. Les types natifs qui disposent d'une méthode @@iterator sont :

- - - -

Pour plus d'informations, voir aussi la page sur les protocoles d'itération.

- -

{{js_property_attributes(0,0,0)}}

- -

Exemples

- -

Itérables définis par l'utilisateur

- -

Il est possible de construire un itérable de la façon suivante :

- -
var monItérable = {}
-monItérable[Symbol.iterator] = function* () {
-    yield 1;
-    yield 2;
-    yield 3;
-};
-[...monItérable] // [1, 2, 3]
-
- -

On peut également définir ces itérables via des propriétés calculées dans des déclarations de classe ou dans des littéraux objets :

- -
class Toto {
-  *[Symbol.iterator] () {
-    yield 1;
-    yield 2;
-    yield 3;
-  }
-}
-
-const monObj = {
-  *[Symbol.iterator] () {
-    yield "a";
-    yield "b";
-  }
-}
-
-[... new Toto] // [1, 2, 3]
-[... monObj]   // ["a", "b"]
-
- -

Itérables mal-formés

- -

Si la méthode @@iterator d'un itérable ne renvoie pas un itérateur, on dira que c'est un itérable mal-formé. Utiliser un tel itérable peut provoquer des erreurs lors de l'exécution :

- -
var itérableMalFormé = {}
-itérableMalFormé[Symbol.iterator] = () => 1
-[...itérableMalFormé] // TypeError: [] is not a function
-
- -

Spécifications

- - - - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.iterator', 'Symbol.iterator')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.iterator', 'Symbol.iterator')}}{{Spec2('ESDraft')}}
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.iterator")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/iterator/index.md b/files/fr/web/javascript/reference/global_objects/symbol/iterator/index.md new file mode 100644 index 0000000000..2b3d9bf367 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/iterator/index.md @@ -0,0 +1,121 @@ +--- +title: Symbol.iterator +slug: Web/JavaScript/Reference/Global_Objects/Symbol/iterator +tags: + - ECMAScript 2015 + - JavaScript + - Propriété + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/iterator +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/iterator +--- +
{{JSRef}}
+ +

Le symbole Symbol.iterator définit l'itérateur par défaut d'un objet. C'est l'itérateur qui sera utilisé par for...of.

+ +
{{EmbedInteractiveExample("pages/js/symbol-iterator.html")}}
+ + + +

Description

+ +

Lorsqu'on doit itérer sur un objet (par exemple avec une boucle for..of), sa méthode @@iterator est appelée sans argument et l'itérateur renvoyé par la méthode est utilisé pour récupérer les valeurs sur lesquelles itérer.

+ +

Certains types natifs possèdent un comportement par défaut pour l'itération, d'autres types (tels qu'{{jsxref("Object")}}) n'ont pas de tel comportement. Les types natifs qui disposent d'une méthode @@iterator sont :

+ + + +

Pour plus d'informations, voir aussi la page sur les protocoles d'itération.

+ +

{{js_property_attributes(0,0,0)}}

+ +

Exemples

+ +

Itérables définis par l'utilisateur

+ +

Il est possible de construire un itérable de la façon suivante :

+ +
var monItérable = {}
+monItérable[Symbol.iterator] = function* () {
+    yield 1;
+    yield 2;
+    yield 3;
+};
+[...monItérable] // [1, 2, 3]
+
+ +

On peut également définir ces itérables via des propriétés calculées dans des déclarations de classe ou dans des littéraux objets :

+ +
class Toto {
+  *[Symbol.iterator] () {
+    yield 1;
+    yield 2;
+    yield 3;
+  }
+}
+
+const monObj = {
+  *[Symbol.iterator] () {
+    yield "a";
+    yield "b";
+  }
+}
+
+[... new Toto] // [1, 2, 3]
+[... monObj]   // ["a", "b"]
+
+ +

Itérables mal-formés

+ +

Si la méthode @@iterator d'un itérable ne renvoie pas un itérateur, on dira que c'est un itérable mal-formé. Utiliser un tel itérable peut provoquer des erreurs lors de l'exécution :

+ +
var itérableMalFormé = {}
+itérableMalFormé[Symbol.iterator] = () => 1
+[...itérableMalFormé] // TypeError: [] is not a function
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.iterator', 'Symbol.iterator')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.iterator', 'Symbol.iterator')}}{{Spec2('ESDraft')}}
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.iterator")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/keyfor/index.html b/files/fr/web/javascript/reference/global_objects/symbol/keyfor/index.html deleted file mode 100644 index 804b089fe1..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/keyfor/index.html +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: Symbol.keyFor() -slug: Web/JavaScript/Reference/Global_Objects/Symbol/keyFor -tags: - - ECMAScript 2015 - - JavaScript - - Méthode - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/keyFor -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/keyFor ---- -
{{JSRef}}
- -

La méthode Symbol.keyFor(sym) permet de récupérer la clé d'un symbole donné qui est partagé via le registre global des symboles.

- -
{{EmbedInteractiveExample("pages/js/symbol-keyfor.html")}}
- -

Syntaxe

- -
Symbol.keyFor(sym);
- -

Paramètres

- -
-
sym
-
Le symbole dont on souhaite connaître la clé. Ce paramètre est obligatoire.
-
- -

Valeur de retour

- -

Une chaîne de caractères qui représente la clé d'un symbole donné si celui-ci est trouvé dans le registre global ou {{jsxref("undefined")}} sinon.

- -

Exemples

- -
var symboleGlobal = Symbol.for("toto"); // on crée un symbole global
-Symbol.keyFor(symboleGlobal); // "toto"
-
-var symboleLocal = Symbol();
-Symbol.keyFor(symboleLocal); // undefined
-
-// les symboles connus ne sont pas dans le registre
-// global
-Symbol.keyFor(Symbol.iterator); // undefined
-
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.keyfor', 'Symbol.keyFor')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.keyfor', 'Symbol.keyFor')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.keyFor")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/keyfor/index.md b/files/fr/web/javascript/reference/global_objects/symbol/keyfor/index.md new file mode 100644 index 0000000000..804b089fe1 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/keyfor/index.md @@ -0,0 +1,77 @@ +--- +title: Symbol.keyFor() +slug: Web/JavaScript/Reference/Global_Objects/Symbol/keyFor +tags: + - ECMAScript 2015 + - JavaScript + - Méthode + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/keyFor +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/keyFor +--- +
{{JSRef}}
+ +

La méthode Symbol.keyFor(sym) permet de récupérer la clé d'un symbole donné qui est partagé via le registre global des symboles.

+ +
{{EmbedInteractiveExample("pages/js/symbol-keyfor.html")}}
+ +

Syntaxe

+ +
Symbol.keyFor(sym);
+ +

Paramètres

+ +
+
sym
+
Le symbole dont on souhaite connaître la clé. Ce paramètre est obligatoire.
+
+ +

Valeur de retour

+ +

Une chaîne de caractères qui représente la clé d'un symbole donné si celui-ci est trouvé dans le registre global ou {{jsxref("undefined")}} sinon.

+ +

Exemples

+ +
var symboleGlobal = Symbol.for("toto"); // on crée un symbole global
+Symbol.keyFor(symboleGlobal); // "toto"
+
+var symboleLocal = Symbol();
+Symbol.keyFor(symboleLocal); // undefined
+
+// les symboles connus ne sont pas dans le registre
+// global
+Symbol.keyFor(Symbol.iterator); // undefined
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.keyfor', 'Symbol.keyFor')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.keyfor', 'Symbol.keyFor')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.keyFor")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/match/index.html b/files/fr/web/javascript/reference/global_objects/symbol/match/index.html deleted file mode 100644 index c1b0aed572..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/match/index.html +++ /dev/null @@ -1,78 +0,0 @@ ---- -title: Symbol.match -slug: Web/JavaScript/Reference/Global_Objects/Symbol/match -tags: - - ECMAScript 2015 - - JavaScript - - Propriété - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/match -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/match ---- -
{{JSRef}}
- -

Le symbole Symbol.match définit la correspondance d'une expression rationnelle par rapport à une chaîne de caractères. Cette fonction est appelée par la méthode {{jsxref("String.prototype.match()")}}.

- -
{{EmbedInteractiveExample("pages/js/symbol-match.html")}}
- - - -

Description

- -

Cette fonction est également utilisée pour identifier les objets qui jouent un rôle avec les expressions rationnelles. Ainsi, les méthodes {{jsxref("String.prototype.startsWith()")}}, {{jsxref("String.prototype.endsWith()")}} et {{jsxref("String.prototype.includes()")}} vérifient si leur premier argument est une expression rationnelle et lèvent une exception {{jsxref("TypeError")}} si c'est le cas. Si le symbole match est modifié et vaut une valeur false (ou équivalente), cela indique que l'objet ne doit pas être utilisé comme une expression rationnelle.

- -

{{js_property_attributes(0,0,0)}}

- -

Exemples

- -

Le code suivant renverra une exception {{jsxref("TypeError")}} :

- -
"/truc/".startsWith(/truc/);
-
-// lève une TypeError car /truc/
-// est une expression rationnelle
-// et que Symbol.match n'a pas été modifié.
- -

Cependant, si Symbol.match vaut false, cette vérification isRegExp indiquera que l'objet à prendre en compte n'est pas une expression rationnelle. Les méthodes startsWith et endsWith ne déclencheront donc pas d'exception TypeError.

- -
var re = /toto/;
-re[Symbol.match] = false;
-"/toto/".startsWith(re); // true
-"/truc/".endsWith(re);   // false
-
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.match', 'Symbol.match')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.match', 'Symbol.match')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.match")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/match/index.md b/files/fr/web/javascript/reference/global_objects/symbol/match/index.md new file mode 100644 index 0000000000..c1b0aed572 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/match/index.md @@ -0,0 +1,78 @@ +--- +title: Symbol.match +slug: Web/JavaScript/Reference/Global_Objects/Symbol/match +tags: + - ECMAScript 2015 + - JavaScript + - Propriété + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/match +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/match +--- +
{{JSRef}}
+ +

Le symbole Symbol.match définit la correspondance d'une expression rationnelle par rapport à une chaîne de caractères. Cette fonction est appelée par la méthode {{jsxref("String.prototype.match()")}}.

+ +
{{EmbedInteractiveExample("pages/js/symbol-match.html")}}
+ + + +

Description

+ +

Cette fonction est également utilisée pour identifier les objets qui jouent un rôle avec les expressions rationnelles. Ainsi, les méthodes {{jsxref("String.prototype.startsWith()")}}, {{jsxref("String.prototype.endsWith()")}} et {{jsxref("String.prototype.includes()")}} vérifient si leur premier argument est une expression rationnelle et lèvent une exception {{jsxref("TypeError")}} si c'est le cas. Si le symbole match est modifié et vaut une valeur false (ou équivalente), cela indique que l'objet ne doit pas être utilisé comme une expression rationnelle.

+ +

{{js_property_attributes(0,0,0)}}

+ +

Exemples

+ +

Le code suivant renverra une exception {{jsxref("TypeError")}} :

+ +
"/truc/".startsWith(/truc/);
+
+// lève une TypeError car /truc/
+// est une expression rationnelle
+// et que Symbol.match n'a pas été modifié.
+ +

Cependant, si Symbol.match vaut false, cette vérification isRegExp indiquera que l'objet à prendre en compte n'est pas une expression rationnelle. Les méthodes startsWith et endsWith ne déclencheront donc pas d'exception TypeError.

+ +
var re = /toto/;
+re[Symbol.match] = false;
+"/toto/".startsWith(re); // true
+"/truc/".endsWith(re);   // false
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.match', 'Symbol.match')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.match', 'Symbol.match')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.match")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/matchall/index.html b/files/fr/web/javascript/reference/global_objects/symbol/matchall/index.html deleted file mode 100644 index e3fa6b44aa..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/matchall/index.html +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: Symbol.matchAll -slug: Web/JavaScript/Reference/Global_Objects/Symbol/matchAll -tags: - - JavaScript - - Propriété - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/matchAll -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/matchAll ---- -
{{JSRef}}
- -

Le symbole connu Symbol.matchAll renvoie un itérateur qui fournit l'ensemble des correspondances entre une expression rationnelle et une chaîne de caractères. Cette fonction est implicitement appelée par la méthode {{jsxref("String.prototype.matchAll()")}}.

- -
{{EmbedInteractiveExample("pages/js/symbol-matchall.html")}}
- -

Description

- -
-

Ce symbole est utilisé par {{jsxref("String.prototype.matchAll()")}} et plus particulièrement par {{jsxref("RegExp.@@matchAll", "RegExp.prototype[@@matchAll]()")}}. Les deux lignes qui suivent renverront le même résultat :

- -
'abc'.matchAll(/a/);
-
-/a/[Symbol.matchAll]('abc');
- -

Cette méthode existe afin de personnaliser le comportement des correspondances pour les sous-classes de {{jsxref("RegExp")}}.

- -

{{js_property_attributes(0,0,0)}}

-
- -

Exemples

- -

Voir les pages {{jsxref("String.prototype.matchAll()")}} et {{jsxref("RegExp.@@matchAll", "RegExp.prototype[@@matchAll]()")}} pour plus d'exemples.

- -

Spécifications

- - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ESDraft', '#sec-symbol.matchall', 'Symbol.matchAll')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.matchAll")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/matchall/index.md b/files/fr/web/javascript/reference/global_objects/symbol/matchall/index.md new file mode 100644 index 0000000000..e3fa6b44aa --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/matchall/index.md @@ -0,0 +1,64 @@ +--- +title: Symbol.matchAll +slug: Web/JavaScript/Reference/Global_Objects/Symbol/matchAll +tags: + - JavaScript + - Propriété + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/matchAll +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/matchAll +--- +
{{JSRef}}
+ +

Le symbole connu Symbol.matchAll renvoie un itérateur qui fournit l'ensemble des correspondances entre une expression rationnelle et une chaîne de caractères. Cette fonction est implicitement appelée par la méthode {{jsxref("String.prototype.matchAll()")}}.

+ +
{{EmbedInteractiveExample("pages/js/symbol-matchall.html")}}
+ +

Description

+ +
+

Ce symbole est utilisé par {{jsxref("String.prototype.matchAll()")}} et plus particulièrement par {{jsxref("RegExp.@@matchAll", "RegExp.prototype[@@matchAll]()")}}. Les deux lignes qui suivent renverront le même résultat :

+ +
'abc'.matchAll(/a/);
+
+/a/[Symbol.matchAll]('abc');
+ +

Cette méthode existe afin de personnaliser le comportement des correspondances pour les sous-classes de {{jsxref("RegExp")}}.

+ +

{{js_property_attributes(0,0,0)}}

+
+ +

Exemples

+ +

Voir les pages {{jsxref("String.prototype.matchAll()")}} et {{jsxref("RegExp.@@matchAll", "RegExp.prototype[@@matchAll]()")}} pour plus d'exemples.

+ +

Spécifications

+ + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ESDraft', '#sec-symbol.matchall', 'Symbol.matchAll')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.matchAll")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/replace/index.html b/files/fr/web/javascript/reference/global_objects/symbol/replace/index.html deleted file mode 100644 index 8b8e11ecbb..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/replace/index.html +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: Symbol.replace -slug: Web/JavaScript/Reference/Global_Objects/Symbol/replace -tags: - - ECMAScript 2015 - - JavaScript - - Propriété - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/replace -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/replace ---- -
{{JSRef}}
- -

Le symbole connu Symbol.replace définit la méthode utilisée pour remplacer les correspondances trouvées dans une chaîne de caractères. Cette fonction est appelée par la méthode {{jsxref("String.prototype.replace()")}}.

- -

Pour plus d'informations, se référer aux pages sur {{jsxref("RegExp.@@replace", "RegExp.prototype[@@replace]()")}} et {{jsxref("String.prototype.replace()")}}.

- -
{{EmbedInteractiveExample("pages/js/symbol-replace.html")}}
- - - -
{{js_property_attributes(0,0,0)}}
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.replace', 'Symbol.replace')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.replace', 'Symbol.replace')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.replace")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/replace/index.md b/files/fr/web/javascript/reference/global_objects/symbol/replace/index.md new file mode 100644 index 0000000000..8b8e11ecbb --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/replace/index.md @@ -0,0 +1,58 @@ +--- +title: Symbol.replace +slug: Web/JavaScript/Reference/Global_Objects/Symbol/replace +tags: + - ECMAScript 2015 + - JavaScript + - Propriété + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/replace +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/replace +--- +
{{JSRef}}
+ +

Le symbole connu Symbol.replace définit la méthode utilisée pour remplacer les correspondances trouvées dans une chaîne de caractères. Cette fonction est appelée par la méthode {{jsxref("String.prototype.replace()")}}.

+ +

Pour plus d'informations, se référer aux pages sur {{jsxref("RegExp.@@replace", "RegExp.prototype[@@replace]()")}} et {{jsxref("String.prototype.replace()")}}.

+ +
{{EmbedInteractiveExample("pages/js/symbol-replace.html")}}
+ + + +
{{js_property_attributes(0,0,0)}}
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.replace', 'Symbol.replace')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.replace', 'Symbol.replace')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.replace")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/search/index.html b/files/fr/web/javascript/reference/global_objects/symbol/search/index.html deleted file mode 100644 index 0b517d7c13..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/search/index.html +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: Symbol.search -slug: Web/JavaScript/Reference/Global_Objects/Symbol/search -tags: - - ECMAScript 2015 - - JavaScript - - Propriété - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/search -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/search ---- -
{{JSRef}}
- -

Le symbole connu Symbol.search définit la méthode qui renvoie l'indice indiquant la position d'une correspondance trouvée dans une chaîne de caractères grâce à une expression rationnelle. Cette fonction est appelée par la méthode {{jsxref("String.prototype.search()")}}.

- -

Pour plus d'informations, se référer aux pages sur {{jsxref("RegExp.@@search", "RegExp.prototype[@@search]()")}} et {{jsxref("String.prototype.search()")}}.

- -
{{EmbedInteractiveExample("pages/js/symbol-search.html")}}
- - - -
{{js_property_attributes(0,0,0)}}
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.search', 'Symbol.search')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.search', 'Symbol.search')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.search")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/search/index.md b/files/fr/web/javascript/reference/global_objects/symbol/search/index.md new file mode 100644 index 0000000000..0b517d7c13 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/search/index.md @@ -0,0 +1,58 @@ +--- +title: Symbol.search +slug: Web/JavaScript/Reference/Global_Objects/Symbol/search +tags: + - ECMAScript 2015 + - JavaScript + - Propriété + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/search +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/search +--- +
{{JSRef}}
+ +

Le symbole connu Symbol.search définit la méthode qui renvoie l'indice indiquant la position d'une correspondance trouvée dans une chaîne de caractères grâce à une expression rationnelle. Cette fonction est appelée par la méthode {{jsxref("String.prototype.search()")}}.

+ +

Pour plus d'informations, se référer aux pages sur {{jsxref("RegExp.@@search", "RegExp.prototype[@@search]()")}} et {{jsxref("String.prototype.search()")}}.

+ +
{{EmbedInteractiveExample("pages/js/symbol-search.html")}}
+ + + +
{{js_property_attributes(0,0,0)}}
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.search', 'Symbol.search')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.search', 'Symbol.search')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.search")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/species/index.html b/files/fr/web/javascript/reference/global_objects/symbol/species/index.html deleted file mode 100644 index 1d533ecbc4..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/species/index.html +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: Symbol.species -slug: Web/JavaScript/Reference/Global_Objects/Symbol/species -tags: - - ECMAScript 2015 - - JavaScript - - Propriété - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/species -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/species ---- -
{{JSRef}}
- -

Le symbole Symbol.species correspond à une fonction utilisée comme constructeur pour créer des objets dérivés.

- -
{{EmbedInteractiveExample("pages/js/symbol-species.html")}}
- - - -

Description

- -

L'accesseur species permettent aux classes filles de surcharger le constructeur par défaut des objets.

- -

{{js_property_attributes(0,0,0)}}

- -

Exemples

- -

Dans certains cas, vous pouvez avoir besoin de renvoyer {{jsxref("Array")}} pour les objets de votre classe dérivée MonArray. Cela permet par exemple d'utiliser le constructeur par défaut lors d'un appel à {{jsxref("Array.map", "map()")}}. De cette façon, ces méthodes renverront un objet Array plutôt qu'un objet MonArray. Grâce au symbole species, vous pouvez donc faire :

- -
class MonArray extends Array {
-  // On surcharge species avec le constructeur parent Array
-  static get [Symbol.species]() { return Array; }
-}
-var a = new MonArray(1,2,3);
-var mapped = a.map(x => x * x);
-
-console.log(mapped instanceof MonArray); // false
-console.log(mapped instanceof Array);    // true
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.species', 'Symbol.species')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.species', 'Symbol.species')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.species")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/species/index.md b/files/fr/web/javascript/reference/global_objects/symbol/species/index.md new file mode 100644 index 0000000000..1d533ecbc4 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/species/index.md @@ -0,0 +1,72 @@ +--- +title: Symbol.species +slug: Web/JavaScript/Reference/Global_Objects/Symbol/species +tags: + - ECMAScript 2015 + - JavaScript + - Propriété + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/species +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/species +--- +
{{JSRef}}
+ +

Le symbole Symbol.species correspond à une fonction utilisée comme constructeur pour créer des objets dérivés.

+ +
{{EmbedInteractiveExample("pages/js/symbol-species.html")}}
+ + + +

Description

+ +

L'accesseur species permettent aux classes filles de surcharger le constructeur par défaut des objets.

+ +

{{js_property_attributes(0,0,0)}}

+ +

Exemples

+ +

Dans certains cas, vous pouvez avoir besoin de renvoyer {{jsxref("Array")}} pour les objets de votre classe dérivée MonArray. Cela permet par exemple d'utiliser le constructeur par défaut lors d'un appel à {{jsxref("Array.map", "map()")}}. De cette façon, ces méthodes renverront un objet Array plutôt qu'un objet MonArray. Grâce au symbole species, vous pouvez donc faire :

+ +
class MonArray extends Array {
+  // On surcharge species avec le constructeur parent Array
+  static get [Symbol.species]() { return Array; }
+}
+var a = new MonArray(1,2,3);
+var mapped = a.map(x => x * x);
+
+console.log(mapped instanceof MonArray); // false
+console.log(mapped instanceof Array);    // true
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.species', 'Symbol.species')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.species', 'Symbol.species')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.species")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/split/index.html b/files/fr/web/javascript/reference/global_objects/symbol/split/index.html deleted file mode 100644 index 46b881a57b..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/split/index.html +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: Symbol.split -slug: Web/JavaScript/Reference/Global_Objects/Symbol/split -tags: - - ECMAScript 2015 - - JavaScript - - Propriété - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/split -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/split ---- -
{{JSRef}}
- -

Le symbole connu Symbol.split définit la méthode qui est utilisée pour découper une chaîne de caractères à l'emplacement où une correspondance a été trouvée grâce à une expression rationnelle. Cette fonction est appelée par la méthode {{jsxref("String.prototype.split()")}}.

- -

Pour plus d'informations, se référer aux pages sur {{jsxref("RegExp.@@split", "RegExp.prototype[@@split]()")}} et {{jsxref("String.prototype.split()")}}.

- -
{{EmbedInteractiveExample("pages/js/symbol-split.html")}}
- - - -
{{js_property_attributes(0,0,0)}}
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.split', 'Symbol.split')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.split', 'Symbol.split')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.split")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/split/index.md b/files/fr/web/javascript/reference/global_objects/symbol/split/index.md new file mode 100644 index 0000000000..46b881a57b --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/split/index.md @@ -0,0 +1,58 @@ +--- +title: Symbol.split +slug: Web/JavaScript/Reference/Global_Objects/Symbol/split +tags: + - ECMAScript 2015 + - JavaScript + - Propriété + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/split +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/split +--- +
{{JSRef}}
+ +

Le symbole connu Symbol.split définit la méthode qui est utilisée pour découper une chaîne de caractères à l'emplacement où une correspondance a été trouvée grâce à une expression rationnelle. Cette fonction est appelée par la méthode {{jsxref("String.prototype.split()")}}.

+ +

Pour plus d'informations, se référer aux pages sur {{jsxref("RegExp.@@split", "RegExp.prototype[@@split]()")}} et {{jsxref("String.prototype.split()")}}.

+ +
{{EmbedInteractiveExample("pages/js/symbol-split.html")}}
+ + + +
{{js_property_attributes(0,0,0)}}
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.split', 'Symbol.split')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.split', 'Symbol.split')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.split")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/toprimitive/index.html b/files/fr/web/javascript/reference/global_objects/symbol/toprimitive/index.html deleted file mode 100644 index 61a0cc823f..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/toprimitive/index.html +++ /dev/null @@ -1,87 +0,0 @@ ---- -title: Symbol.toPrimitive -slug: Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive -tags: - - ECMAScript 2015 - - JavaScript - - Propriété - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/toPrimitive ---- -
{{JSRef}}
- -

Le symbole « connu » Symbol.toPrimitive définit une fonction qui est appelée pour convertir un objet en une valeur primitive.

- -
{{EmbedInteractiveExample("pages/js/symbol-toprimitive.html")}}
- - - -

Description

- -

Lorsqu'on convertit un objet en une valeur primitive et que l'objet possède une propriété Symbol.toPrimitive dont la valeur est une fonction, la fonction est appelée avec une chaîne de caractère (hint) qui définit le type qu'on privilégie pour la valeur primitive. L'argument hint peut prendre l'une des valeurs suivantes : "number", "string" ou "default".

- -

{{js_property_attributes(0,0,0)}}

- -

Exemples

- -

Dans l'exemple qui suit, on voit comment la propriété Symbol.toPrimitive peut modifier la valeur primitive obtenue lors de la conversion d'un objet.

- -
// Premier cas avec un objet sans Symbol.toPrimitive.
-let obj1 = {};
-console.log(+obj1);     // NaN
-console.log(`${obj1}`); // "[object Object]"
-console.log(obj1 + ""); // "[object Object]"
-
-// Second cas : l'objet a une propriété Symbol.toPrimitive
-var obj2 = {
-  [Symbol.toPrimitive](hint) {
-    if (hint === "number") {
-      return 10;
-    }
-    if (hint === "string") {
-      return "coucou";
-    }
-    return true;
-  }
-};
-console.log(+obj2);     // 10       -- hint vaut "number"
-console.log(`${obj2}`); // "coucou" -- hint vaut "string"
-console.log(obj2 + ""); // true     -- hint vaut "default"
-
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationEtatCommentaires
{{SpecName('ES2015', '#sec-symbol.toprimitive', 'Symbol.toPrimitive')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.toprimitive', 'Symbol.toPrimitive')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.toPrimitive")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/toprimitive/index.md b/files/fr/web/javascript/reference/global_objects/symbol/toprimitive/index.md new file mode 100644 index 0000000000..61a0cc823f --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/toprimitive/index.md @@ -0,0 +1,87 @@ +--- +title: Symbol.toPrimitive +slug: Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive +tags: + - ECMAScript 2015 + - JavaScript + - Propriété + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/toPrimitive +--- +
{{JSRef}}
+ +

Le symbole « connu » Symbol.toPrimitive définit une fonction qui est appelée pour convertir un objet en une valeur primitive.

+ +
{{EmbedInteractiveExample("pages/js/symbol-toprimitive.html")}}
+ + + +

Description

+ +

Lorsqu'on convertit un objet en une valeur primitive et que l'objet possède une propriété Symbol.toPrimitive dont la valeur est une fonction, la fonction est appelée avec une chaîne de caractère (hint) qui définit le type qu'on privilégie pour la valeur primitive. L'argument hint peut prendre l'une des valeurs suivantes : "number", "string" ou "default".

+ +

{{js_property_attributes(0,0,0)}}

+ +

Exemples

+ +

Dans l'exemple qui suit, on voit comment la propriété Symbol.toPrimitive peut modifier la valeur primitive obtenue lors de la conversion d'un objet.

+ +
// Premier cas avec un objet sans Symbol.toPrimitive.
+let obj1 = {};
+console.log(+obj1);     // NaN
+console.log(`${obj1}`); // "[object Object]"
+console.log(obj1 + ""); // "[object Object]"
+
+// Second cas : l'objet a une propriété Symbol.toPrimitive
+var obj2 = {
+  [Symbol.toPrimitive](hint) {
+    if (hint === "number") {
+      return 10;
+    }
+    if (hint === "string") {
+      return "coucou";
+    }
+    return true;
+  }
+};
+console.log(+obj2);     // 10       -- hint vaut "number"
+console.log(`${obj2}`); // "coucou" -- hint vaut "string"
+console.log(obj2 + ""); // true     -- hint vaut "default"
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationEtatCommentaires
{{SpecName('ES2015', '#sec-symbol.toprimitive', 'Symbol.toPrimitive')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.toprimitive', 'Symbol.toPrimitive')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.toPrimitive")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/tosource/index.html b/files/fr/web/javascript/reference/global_objects/symbol/tosource/index.html deleted file mode 100644 index 45796e26bb..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/tosource/index.html +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: Symbol.prototype.toSource() -slug: Web/JavaScript/Reference/Global_Objects/Symbol/toSource -tags: - - JavaScript - - Méthode - - Non-standard - - Prototype - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/toSource -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/toSource ---- -
{{JSRef}} {{non-standard_header}}
- -

La méthode toSource() renvoie une chaîne de caractères représentant le code source de l'objet.

- -

L'utilisation de cette méthode est généralement interne au moteur JavaScript.

- -

Syntaxe

- -
Symbol.toSource();
-
-var sym = Symbol();
-sym.toSource();
- -

Valeur de retour

- -

Une chaîne de caractères qui représente le code source de l'objet.

- -

Description

- -

La méthode toSource renvoie les valeurs suivantes :

- - - -

Spécifications

- -

Cette méthode ne fait partie d'aucun standard.

- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.toSource")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/tosource/index.md b/files/fr/web/javascript/reference/global_objects/symbol/tosource/index.md new file mode 100644 index 0000000000..45796e26bb --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/tosource/index.md @@ -0,0 +1,59 @@ +--- +title: Symbol.prototype.toSource() +slug: Web/JavaScript/Reference/Global_Objects/Symbol/toSource +tags: + - JavaScript + - Méthode + - Non-standard + - Prototype + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/toSource +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/toSource +--- +
{{JSRef}} {{non-standard_header}}
+ +

La méthode toSource() renvoie une chaîne de caractères représentant le code source de l'objet.

+ +

L'utilisation de cette méthode est généralement interne au moteur JavaScript.

+ +

Syntaxe

+ +
Symbol.toSource();
+
+var sym = Symbol();
+sym.toSource();
+ +

Valeur de retour

+ +

Une chaîne de caractères qui représente le code source de l'objet.

+ +

Description

+ +

La méthode toSource renvoie les valeurs suivantes :

+ + + +

Spécifications

+ +

Cette méthode ne fait partie d'aucun standard.

+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.toSource")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/tostring/index.html b/files/fr/web/javascript/reference/global_objects/symbol/tostring/index.html deleted file mode 100644 index 7ab3b55791..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/tostring/index.html +++ /dev/null @@ -1,79 +0,0 @@ ---- -title: Symbol.prototype.toString() -slug: Web/JavaScript/Reference/Global_Objects/Symbol/toString -tags: - - ECMAScript 2015 - - JavaScript - - Méthode - - Prototype - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/toString -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/toString ---- -
{{JSRef}}
- -

La méthode toString() renvoie une chaîne de caractères représentant l'objet Symbol.

- -
{{EmbedInteractiveExample("pages/js/symbol-prototype-tostring.html")}}
- -

Syntaxe

- -
Symbol().toString();
- -

Valeur de retour

- -

Une chaîne de caractères qui représente l'objet {{jsxref("Symbol")}}.

- -

Description

- -

L'objet {{jsxref("Symbol")}} surcharge la méthode toString() d'{{jsxref("Object")}} et n'hérite pas de {{jsxref("Object.prototype.toString()")}}. Pour les objets Symbol, la méthode toString() renvoie représentation de l'objet sous forme d'une chaîne de caractères.

- -

Concaténation de chaînes et symboles

- -

Bien qu'il soit possible d'appeler toString() pour les symboles, il n'est pas possible de concaténer une chaîne de caractères avec ce type d'objet :

- -
Symbol("toto") + "machin";  // TypeError : Impossible de convertir un symbole en chaîne de caractères
- -

Exemples

- -
Symbol("desc").toString();   // "Symbol(desc)"
-
-// symboles connus
-Symbol.iterator.toString();  // "Symbol(Symbol.iterator)
-
-// symboles globaux
-Symbol.for("toto").toString() // "Symbol(toto)"
-
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.prototype.tostring', 'Symbol.prototype.toString')}}{{Spec2('ES2015')}}Définition initiale
{{SpecName('ESDraft', '#sec-symbol.prototype.tostring', 'Symbol.prototype.toString')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.toString")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/tostring/index.md b/files/fr/web/javascript/reference/global_objects/symbol/tostring/index.md new file mode 100644 index 0000000000..7ab3b55791 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/tostring/index.md @@ -0,0 +1,79 @@ +--- +title: Symbol.prototype.toString() +slug: Web/JavaScript/Reference/Global_Objects/Symbol/toString +tags: + - ECMAScript 2015 + - JavaScript + - Méthode + - Prototype + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/toString +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/toString +--- +
{{JSRef}}
+ +

La méthode toString() renvoie une chaîne de caractères représentant l'objet Symbol.

+ +
{{EmbedInteractiveExample("pages/js/symbol-prototype-tostring.html")}}
+ +

Syntaxe

+ +
Symbol().toString();
+ +

Valeur de retour

+ +

Une chaîne de caractères qui représente l'objet {{jsxref("Symbol")}}.

+ +

Description

+ +

L'objet {{jsxref("Symbol")}} surcharge la méthode toString() d'{{jsxref("Object")}} et n'hérite pas de {{jsxref("Object.prototype.toString()")}}. Pour les objets Symbol, la méthode toString() renvoie représentation de l'objet sous forme d'une chaîne de caractères.

+ +

Concaténation de chaînes et symboles

+ +

Bien qu'il soit possible d'appeler toString() pour les symboles, il n'est pas possible de concaténer une chaîne de caractères avec ce type d'objet :

+ +
Symbol("toto") + "machin";  // TypeError : Impossible de convertir un symbole en chaîne de caractères
+ +

Exemples

+ +
Symbol("desc").toString();   // "Symbol(desc)"
+
+// symboles connus
+Symbol.iterator.toString();  // "Symbol(Symbol.iterator)
+
+// symboles globaux
+Symbol.for("toto").toString() // "Symbol(toto)"
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.prototype.tostring', 'Symbol.prototype.toString')}}{{Spec2('ES2015')}}Définition initiale
{{SpecName('ESDraft', '#sec-symbol.prototype.tostring', 'Symbol.prototype.toString')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.toString")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/tostringtag/index.html b/files/fr/web/javascript/reference/global_objects/symbol/tostringtag/index.html deleted file mode 100644 index a5c2a0a439..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/tostringtag/index.html +++ /dev/null @@ -1,92 +0,0 @@ ---- -title: Symbol.toStringTag -slug: Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag -tags: - - ECMAScript 2015 - - JavaScript - - Propriété - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/toStringTag ---- -
{{JSRef}}
- -

Le symbole connu Symbol.toStringTag est une propriété qui est une chaîne de caractères qui est utilisée pour la description textuelle par défaut d'un objet. Ce symbole est utilisé par le moteur JavaScript via la méthode {{jsxref("Object.prototype.toString()")}}.

- -
{{EmbedInteractiveExample("pages/js/symbol-tostringtag.html")}}
- - - -
{{js_property_attributes(0,0,0)}}
- -

Description

- -

La plupart des types JavaScript ont des étiquettes par défaut :

- -
Object.prototype.toString.call('toto');    // "[object String]"
-Object.prototype.toString.call([1, 2]);    // "[object Array]"
-Object.prototype.toString.call(3);         // "[object Number]"
-Object.prototype.toString.call(true);      // "[object Boolean]"
-Object.prototype.toString.call(undefined); // "[object Undefined]"
-Object.prototype.toString.call(null);      // "[object Null]"
-// etc.
-
- -

D'autres ont le symbole natif toStringTag défini :

- -
Object.prototype.toString.call(new Map());         // "[object Map]"
-Object.prototype.toString.call(function* () {});   // "[object GeneratorFunction]"
-Object.prototype.toString.call(Promise.resolve()); // "[object Promise]"
-// etc.
-
- -

Lorsqu'on crée des classes personnalisées, JavaScript utilise l'étiquette "Object" par défaut :

- -
class ValidatorClass {}
-
-Object.prototype.toString.call(new ValidatorClass()); // "[object Object]"
-
- -

Si on utilise le symbole toStringTag on peut définir une étiquette personnalisée :

- -
class ValidatorClass {
-  get [Symbol.toStringTag]() {
-    return "Validator";
-  }
-}
-
-Object.prototype.toString.call(new ValidatorClass()); // "[object Validator]"
-
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.tostringtag', 'Symbol.toStringTag')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.tostringtag', 'Symbol.toStringTag')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.toStringTag")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/tostringtag/index.md b/files/fr/web/javascript/reference/global_objects/symbol/tostringtag/index.md new file mode 100644 index 0000000000..a5c2a0a439 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/tostringtag/index.md @@ -0,0 +1,92 @@ +--- +title: Symbol.toStringTag +slug: Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag +tags: + - ECMAScript 2015 + - JavaScript + - Propriété + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/toStringTag +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/toStringTag +--- +
{{JSRef}}
+ +

Le symbole connu Symbol.toStringTag est une propriété qui est une chaîne de caractères qui est utilisée pour la description textuelle par défaut d'un objet. Ce symbole est utilisé par le moteur JavaScript via la méthode {{jsxref("Object.prototype.toString()")}}.

+ +
{{EmbedInteractiveExample("pages/js/symbol-tostringtag.html")}}
+ + + +
{{js_property_attributes(0,0,0)}}
+ +

Description

+ +

La plupart des types JavaScript ont des étiquettes par défaut :

+ +
Object.prototype.toString.call('toto');    // "[object String]"
+Object.prototype.toString.call([1, 2]);    // "[object Array]"
+Object.prototype.toString.call(3);         // "[object Number]"
+Object.prototype.toString.call(true);      // "[object Boolean]"
+Object.prototype.toString.call(undefined); // "[object Undefined]"
+Object.prototype.toString.call(null);      // "[object Null]"
+// etc.
+
+ +

D'autres ont le symbole natif toStringTag défini :

+ +
Object.prototype.toString.call(new Map());         // "[object Map]"
+Object.prototype.toString.call(function* () {});   // "[object GeneratorFunction]"
+Object.prototype.toString.call(Promise.resolve()); // "[object Promise]"
+// etc.
+
+ +

Lorsqu'on crée des classes personnalisées, JavaScript utilise l'étiquette "Object" par défaut :

+ +
class ValidatorClass {}
+
+Object.prototype.toString.call(new ValidatorClass()); // "[object Object]"
+
+ +

Si on utilise le symbole toStringTag on peut définir une étiquette personnalisée :

+ +
class ValidatorClass {
+  get [Symbol.toStringTag]() {
+    return "Validator";
+  }
+}
+
+Object.prototype.toString.call(new ValidatorClass()); // "[object Validator]"
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.tostringtag', 'Symbol.toStringTag')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.tostringtag', 'Symbol.toStringTag')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.toStringTag")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/unscopables/index.html b/files/fr/web/javascript/reference/global_objects/symbol/unscopables/index.html deleted file mode 100644 index 4ec9b35407..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/unscopables/index.html +++ /dev/null @@ -1,92 +0,0 @@ ---- -title: Symbol.unscopables -slug: Web/JavaScript/Reference/Global_Objects/Symbol/unscopables -tags: - - ECMAScript 2015 - - JavaScript - - Propriété - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/unscopables -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/unscopables ---- -
{{JSRef}}
- -

Le symbole connu Symbol.unscopables est utilisé afin de définir les noms des propriétés propres et héritées qui sont exclues de l'objet lors de l'utilisation de with sur l'objet en question.

- -
{{EmbedInteractiveExample("pages/js/symbol-unscopables.html")}}
- - - -

Description

- -

Le symbole @@unscopables (Symbol.unscopables) peut être défini sur n'importe quel objet afin de ne pas exposer certaines propriétés lors des liaisons lexicales avec with. Note : en mode strict, l'instruction with n'est pas disponible et ce symbole est donc probablement moins nécessaire.

- -

En définissant une propriété comme true dans un objet unscopables, cela exclura la propriété de la portée lexicale. En définissant une propriété comme false, celle-ci pourra faire partie de la portée lexicale et être manipulée dans un bloc with.

- -

{{js_property_attributes(0,0,0)}}

- -

Exemples

- -

Le code qui suit fonctionne bien pour ES5 et les versions antérieures. En revanche, pour ECMAScript 2015 (ES6) et les versions ultérieures où la méthode  {{jsxref("Array.prototype.keys()")}} existe, lorsqu'on utilise un environnement créé avec with, "keys" serait désormais la méthode et non la variable. C'est là que le symbole natif @@unscopables Array.prototype[@@unscopables] intervient et empêche d'explorer ces méthodes avec with.

- -
var keys = [];
-
-with(Array.prototype) {
-  keys.push("something");
-}
-
-Object.keys(Array.prototype[Symbol.unscopables]);
-// ["copyWithin", "entries", "fill", "find", "findIndex",
-//  "includes", "keys", "values"]
- -

On peut également manipuler unscopables sur ses propres objets :

- -
var obj = {
-  toto: 1,
-  truc: 2
-};
-
-obj[Symbol.unscopables] = {
-  toto: false,
-  truc: true
-};
-
-with(obj) {
-  console.log(toto); // 1
-  console.log(truc); // ReferenceError: truc is not defined
-}
-
- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.unscopables', 'Symbol.unscopables')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.unscopables', 'Symbol.unscopables')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.unscopables")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/unscopables/index.md b/files/fr/web/javascript/reference/global_objects/symbol/unscopables/index.md new file mode 100644 index 0000000000..4ec9b35407 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/unscopables/index.md @@ -0,0 +1,92 @@ +--- +title: Symbol.unscopables +slug: Web/JavaScript/Reference/Global_Objects/Symbol/unscopables +tags: + - ECMAScript 2015 + - JavaScript + - Propriété + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/unscopables +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/unscopables +--- +
{{JSRef}}
+ +

Le symbole connu Symbol.unscopables est utilisé afin de définir les noms des propriétés propres et héritées qui sont exclues de l'objet lors de l'utilisation de with sur l'objet en question.

+ +
{{EmbedInteractiveExample("pages/js/symbol-unscopables.html")}}
+ + + +

Description

+ +

Le symbole @@unscopables (Symbol.unscopables) peut être défini sur n'importe quel objet afin de ne pas exposer certaines propriétés lors des liaisons lexicales avec with. Note : en mode strict, l'instruction with n'est pas disponible et ce symbole est donc probablement moins nécessaire.

+ +

En définissant une propriété comme true dans un objet unscopables, cela exclura la propriété de la portée lexicale. En définissant une propriété comme false, celle-ci pourra faire partie de la portée lexicale et être manipulée dans un bloc with.

+ +

{{js_property_attributes(0,0,0)}}

+ +

Exemples

+ +

Le code qui suit fonctionne bien pour ES5 et les versions antérieures. En revanche, pour ECMAScript 2015 (ES6) et les versions ultérieures où la méthode  {{jsxref("Array.prototype.keys()")}} existe, lorsqu'on utilise un environnement créé avec with, "keys" serait désormais la méthode et non la variable. C'est là que le symbole natif @@unscopables Array.prototype[@@unscopables] intervient et empêche d'explorer ces méthodes avec with.

+ +
var keys = [];
+
+with(Array.prototype) {
+  keys.push("something");
+}
+
+Object.keys(Array.prototype[Symbol.unscopables]);
+// ["copyWithin", "entries", "fill", "find", "findIndex",
+//  "includes", "keys", "values"]
+ +

On peut également manipuler unscopables sur ses propres objets :

+ +
var obj = {
+  toto: 1,
+  truc: 2
+};
+
+obj[Symbol.unscopables] = {
+  toto: false,
+  truc: true
+};
+
+with(obj) {
+  console.log(toto); // 1
+  console.log(truc); // ReferenceError: truc is not defined
+}
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.unscopables', 'Symbol.unscopables')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.unscopables', 'Symbol.unscopables')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.unscopables")}}

+ +

Voir aussi

+ + diff --git a/files/fr/web/javascript/reference/global_objects/symbol/valueof/index.html b/files/fr/web/javascript/reference/global_objects/symbol/valueof/index.html deleted file mode 100644 index 48d99785a5..0000000000 --- a/files/fr/web/javascript/reference/global_objects/symbol/valueof/index.html +++ /dev/null @@ -1,63 +0,0 @@ ---- -title: Symbol.prototype.valueOf() -slug: Web/JavaScript/Reference/Global_Objects/Symbol/valueOf -tags: - - ECMAScript 2015 - - JavaScript - - Méthode - - Prototype - - Reference - - Symbol -translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/valueOf -original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/valueOf ---- -
{{JSRef}}
- -

La méthode valueOf() renvoie la valeur primitive correspondant à l'objet Symbol.

- -

Syntaxe

- -
Symbol().valueOf();
-
- -

Valeur de retour

- -

La valeur primitive de l'objet {{jsxref("Symbol")}} indiqué.

- -

Description

- -

La méthode valueOf de {{jsxref("Symbol")}} renvoie une valeur dont le type est le type primitif symbole à partir de l'objet Symbol donné.

- -

JavaScript appelle la méthode valueOf afin de convertir l'objet en une valeur primitive. La plupart du temps, il n'est pas nécessaire d'appeler explicitement la méthode valueOf. JavaScript l'appelle automatiquement dans les cas où une valeur primitive est attendue.

- -

Spécifications

- - - - - - - - - - - - - - - - - - - -
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.prototype.valueof', 'Symbol.prototype.valueOf')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.prototype.valueof', 'Symbol.prototype.valueOf')}}{{Spec2('ESDraft')}} 
- -

Compatibilité des navigateurs

- -

{{Compat("javascript.builtins.Symbol.valueOf")}}

- -

Voir aussi

- - diff --git a/files/fr/web/javascript/reference/global_objects/symbol/valueof/index.md b/files/fr/web/javascript/reference/global_objects/symbol/valueof/index.md new file mode 100644 index 0000000000..48d99785a5 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/symbol/valueof/index.md @@ -0,0 +1,63 @@ +--- +title: Symbol.prototype.valueOf() +slug: Web/JavaScript/Reference/Global_Objects/Symbol/valueOf +tags: + - ECMAScript 2015 + - JavaScript + - Méthode + - Prototype + - Reference + - Symbol +translation_of: Web/JavaScript/Reference/Global_Objects/Symbol/valueOf +original_slug: Web/JavaScript/Reference/Objets_globaux/Symbol/valueOf +--- +
{{JSRef}}
+ +

La méthode valueOf() renvoie la valeur primitive correspondant à l'objet Symbol.

+ +

Syntaxe

+ +
Symbol().valueOf();
+
+ +

Valeur de retour

+ +

La valeur primitive de l'objet {{jsxref("Symbol")}} indiqué.

+ +

Description

+ +

La méthode valueOf de {{jsxref("Symbol")}} renvoie une valeur dont le type est le type primitif symbole à partir de l'objet Symbol donné.

+ +

JavaScript appelle la méthode valueOf afin de convertir l'objet en une valeur primitive. La plupart du temps, il n'est pas nécessaire d'appeler explicitement la méthode valueOf. JavaScript l'appelle automatiquement dans les cas où une valeur primitive est attendue.

+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-symbol.prototype.valueof', 'Symbol.prototype.valueOf')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-symbol.prototype.valueof', 'Symbol.prototype.valueOf')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +

{{Compat("javascript.builtins.Symbol.valueOf")}}

+ +

Voir aussi

+ + -- cgit v1.2.3-54-g00ecf