Symbol.prototype.description

这篇翻译不完整。请帮忙从英语翻译这篇文章

description 是一个只读属性,它会返回 Symbol 对象的可选描述的字符串。

语法

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

浏览器兼容

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
descriptionChrome Full support 70Edge No support NoFirefox Full support 63IE No support NoOpera Full support 57Safari Full support 12.1
Full support 12.1
Partial support 12
Notes
Notes No support for an undefined description.
WebView Android Full support 70Chrome Android Full support 70Firefox Android Full support 63Opera Android Full support 49Safari iOS Full support 12.2
Full support 12.2
Partial support 12
Notes
Notes No support for an undefined description.
Samsung Internet Android No support Nonodejs No support No

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

另请参阅

文档标签和贡献者

此页面的贡献者: mdnwebdocs-bot, Maiko
最后编辑者: mdnwebdocs-bot,