Symbol.prototype[@@toPrimitive]

[@@toPrimitive]() 方法可将 Symbol 对象转换为原始值。

语法

Symbol()[Symbol.toPrimitive](hint);

返回值

该原始值为指定的 Symbol 对象

描述

 Symbol 的 [@@toPrimitive]() 方法返回该 Symbol 对象原始值作为 Symbol 数据形式。 hint 参数未被使用。

JavaScript 调用 [@@toPrimitive]() 方法将一个对象转换为原始值表示。你不需要自己调用 [@@toPrimitive]() 方法;当对象需要被转换为原始值时,JavaScript 会自动地调用该方法。

规范

Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
Symbol.prototype.@@toPrimitive
Standard Initial definition.
ECMAScript Latest Draft (ECMA-262)
Symbol.prototype.@@toPrimitive
Draft

浏览器兼容性

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
@@toPrimitive Chrome Full support 47 Edge Full support 15 Firefox Full support 44 IE No support No Opera Full support 34 Safari ? WebView Android Full support 47 Chrome Android Full support 47 Firefox Android Full support 44 Opera Android Full support 34 Safari iOS ? Samsung Internet Android Full support 5.0 nodejs ?

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

参考资料