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
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
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
Full support 12.1
Partial support 12
Notes
Notes No support for an undefined description.
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
Full support 12.2
Partial support 12
Notes
Notes No support for an undefined description.
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.

另请参阅