description 是一个只读属性,它会返回 Symbol 对象的可选描述的字符串。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
语法
Symbol('myDescription').description;
Symbol.iterator.description;
Symbol.for('foo').description;
描述
Symbol 对象可以通过一个可选的描述创建,可用于调试,但不能用于访问 symbol 本身。Symbol.prototype.description 属性可以用于读取该描述。与 Symbol.prototype.toString() 不同的是它不会包含 "Symbol()" 的字符串。具体请看实例。
实例
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 | Status |
|---|---|
get Symbol.prototype.description proposal |
Stage 3 |
浏览器兼容
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.
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
description |
Chrome Full support 70 | Edge No support No | Firefox Full support 63 | IE No support No | Opera Full support 57 | Safari Full support 12.1
|
WebView Android Full support 70 | Chrome Android Full support 70 | Firefox Android Full support 63 | Opera Android Full support 49 | Safari iOS Full support 12.2
|
Samsung Internet Android Full support 10.0 | nodejs Full support 11.0.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.
- See implementation notes.