get Array[@@species]

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

语法

Array[Symbol.species]

返回值

Array 的构造函数。

描述

species 访问器属性返回 Array 对象的默认构造函数。子类的构造函数可能会覆盖并改变构造函数的赋值。

示例

species 属性返回默认构造函数, 它用于 Array 对象的构造函数 Array:

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

在继承类的对象中(例如你自定义的数组 MyArray),MyArray 的 species 属性返回的是 MyArray 这个构造函数. 然而你可能想要覆盖它,以便在你继承的对象 MyArray 中返回父类的构造函数 Array :

class MyArray extends Array {
  // 重写 MyArray 的 species 属性到父类 Array 的构造函数
  static get [Symbol.species]() { return Array; }
}

规范

规范 状态 备注
ECMAScript 2015 (6th Edition, ECMA-262)
get Array [ @@species ]
Standard Initial definition.
ECMAScript Latest Draft (ECMA-262)
get Array [ @@species ]
Draft

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
@@speciesChrome Full support 51Edge No support NoFirefox Full support 48IE No support NoOpera Full support 38Safari Full support 10WebView Android Full support 51Chrome Android Full support 51Firefox Android Full support 48Opera 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.

参见