[@@toPrimitive]() method converts a Symbol object to a primitive value.

句法

Symbol()[Symbol.toPrimitive](hint)
					

返回值

The primitive value of the specified Symbol 对象。

描述

[@@toPrimitive]() 方法为 Symbol returns the primitive value of a Symbol object as a Symbol data type. The hint argument is not used.

JavaScript calls the [@@toPrimitive]() method to convert an object to a primitive value. You rarely need to invoke the [@@toPrimitive]() method yourself; JavaScript automatically invokes it when encountering an object where a primitive value is expected.

范例

Using @@toPrimitive

const sym = Symbol("example");
sym === sym[Symbol.toPrimitive](); // true
					

规范

规范
ECMAScript (ECMA-262)
The definition of 'Symbol.prototype.@@toPrimitive' in that specification.

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 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 47 Edge 15 Firefox 44 IE No Opera 34 Safari 10 WebView Android 47 Chrome Android 47 Firefox Android 44 Opera Android 34 Safari iOS 10 Samsung Internet Android 5.0 nodejs 6.0.0

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: