Symbol.prototype.description

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

Exemple interactif

Syntaxe

js
Symbol("maDescription").description;
Symbol.iterator.description;
Symbol.for("toto").description;

Description

Les objets 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

js
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

Specification
ECMAScript Language Specification
# sec-symbol.prototype.description

Compatibilité des navigateurs

BCD tables only load in the browser

Voir aussi