get Set[@@species]

Set[@@species] 访问器属性返回Set的构造函数.

描述

species 访问属性返回 Set 对象的默认构造函数. 子构造函数或许会重载这个属性以至改变构造函数的赋值.

示例

普通对象中的 Species

species 属性返回默认的构造函数, 它是Set 对象的构造函数:

Set[Symbol.species]; // function Set()

派生对象中的 Species

在一个派生集合对象中 (比如你自定义的MySet集合),  MySet 的species 属性 是 MySet 构造函数. 又或者, 你想要重写它, 让它能在你派生的类方法中能返回父级Set 对象:

class MySet extends Set {
  // Overwrite MySet species to the parent Set constructor
  static get [Symbol.species]() { return Set; }
}

规范

Specification
ECMAScript (ECMA-262)
get Set [ @@species ]

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
@@speciesChrome Full support 51Edge Full support 13Firefox Full support 41IE No support NoOpera Full support 38Safari Full support 10WebView Android Full support 51Chrome Android Full support 51Firefox Android Full support 41Opera Android Full support 41Safari iOS Full support 10Samsung Internet Android Full support 5.0nodejs Full support 6.5.0
Full support 6.5.0
Full support 6.0.0
Disabled
Disabled From version 6.0.0: this feature is behind the --harmony runtime flag.

Legend

Full support  
Full support
No support  
No support
User must explicitly enable this feature.
User must explicitly enable this feature.

另见