Symbol.prototype.description
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.
description
は Symbol
値のアクセサープロパティで、このシンボルの説明を格納した文字列を返し、シンボルに説明がない場合は undefined
を返します。
試してみましょう
console.log(Symbol("desc").description);
// Expected output: "desc"
console.log(Symbol.iterator.description);
// Expected output: "Symbol.iterator"
console.log(Symbol.for("foo").description);
// Expected output: "foo"
console.log(`${Symbol("foo").description}bar`);
// Expected output: "foobar"
解説
Symbol
オブジェクトは、オプションの説明を使用して作成できます。これはデバッグには使用できますが、シンボル自体にはアクセスできません。Symbol.prototype.description
プロパティを使用して、その説明を読み取ることができます。囲んでいる "Symbol()
" 文字列が含まれていないため、 Symbol.prototype.toString()
とは異なります。例を参照してください。
例
description を使用する
js
Symbol("desc").toString(); // "Symbol(desc)"
Symbol("desc").description; // "desc"
Symbol("").description; // ""
Symbol().description; // undefined
// well-known symbols
Symbol.iterator.toString(); // "Symbol(Symbol.iterator)"
Symbol.iterator.description; // "Symbol.iterator"
// global symbols
Symbol.for("foo").toString(); // "Symbol(foo)"
Symbol.for("foo").description; // "foo"
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-symbol.prototype.description |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
description |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Partial support
- Partial support
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.