ArrayBuffer.@@species

ArrayBuffer.@@species

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

语法

ArrayBuffer[Symbol.species]

描述

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

示例

返回默认的 ArrayBuffer 构造器:

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

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

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

规范

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'get ArrayBuffer @@species ' in that specification.StandardInitial definition.
ECMAScript 2017 Draft (ECMA-262)The definition of 'get ArrayBuffer @@species ' in that specification.Draft

浏览器兼容性

FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support?48 (48)???

FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support??48.0 (48)???