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 AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
Basic supportChrome Full support 70Edge No support NoFirefox Full support 63IE No support NoOpera Full support 57Safari No support NoWebView Android Full support 70Chrome Android Full support 70Edge Mobile No support NoFirefox Android Full support 63Opera Android Full support 57Safari iOS No support NoSamsung Internet Android No support Nonodejs No support No

Legend

Full support  
Full support
No support  
No support

另请参阅

文档标签和贡献者

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