get ArrayBuffer[@@species]

该 ArrayBuffer[@@species] 访问器属性会返回 ArrayBuffer 构造器。

语法

ArrayBuffer[Symbol.species]

描述

这个 species 访问器属性会返回默认的 ArrayBuffer 构造器。子类构造器可能会覆盖它以改变构造器赋值。

示例

返回默认的 ArrayBuffer 构造器:

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

在派生集合对象中(比如你定制的 array buffer MyArrayBuffer),MyArrayBuffer species 就是 MyArrayBuffer 构造器。但是,你可能想要在派生类里重写它,以期返回的是父类的 ArrayBuffer 对象:

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

规范

Specification Status Comment
ECMAScript 2015 (6th Edition, ECMA-262)
get ArrayBuffer [ @@species ]
Standard Initial definition.
ECMAScript Latest Draft (ECMA-262)
get ArrayBuffer [ @@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 Full support 13Firefox 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.

相关