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 (ECMA-262)
Symbol.prototype.@@toPrimitive
Living Standard

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
@@toPrimitiveChrome Full support 47Edge Full support 15Firefox Full support 44IE No support NoOpera Full support 34Safari Full support 10WebView Android Full support 47Chrome Android Full support 47Firefox Android Full support 44Opera Android Full support 34Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.0.0

Legend

Full support  
Full support
No support  
No support

参考资料