TypedArray.@@species

TypedArray.@@species

TypedArray[@@species]访问器属性返回类型化数组的构造器。

语法

TypedArray[Symbol.species] where TypedArray is one of: Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array

描述

species访问器属性返回类型化数组对象的构造器。 子类的构造器可能会覆盖它来修改构造器的赋值。

示例

species属性返回默认的构造器函数,对于给定的类型化数组对象,它是类型化数组构造器之一:

Int8Array[Symbol.species]; // function Int8Array() Uint8Array[Symbol.species]; // function Uint8Array() Float32Array[Symbol.species]; // function Float32Array()

在派生的集合对象中 (也就是你自己定义的类型化数组MyTypedArray),MyTypedArray的 species 是MyTypedArray构造器。但是,你可能希望覆盖它,以便在你的派生类方法中返回类型化数组的基类对象:

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

规范

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'get %TypedArray% @@species ' in that specification.StandardInitial definition.
ECMAScript Latest Draft (ECMA-262)The definition of 'get %TypedArray% @@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)???