TypedArray[@@species] 访问器属性返回类型化数组的构造器。
语法
TypedArray[Symbol.species] 其中TypedArray是下列类型之一: 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 {
// 将 MyTypedArray species 覆盖为 Uint8Array 基类构造器
static get [Symbol.species]() { return Uint8Array; }
}
规范
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) get %TypedArray% [ @@species ] |
Standard | 初始定义。 |
| ECMAScript Latest Draft (ECMA-262) get %TypedArray% [ @@species ] |
Draft |
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains.
Find out how you can help!
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | ? | 48 (48) | ? | ? | ? |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | ? | ? | 48.0 (48) | ? | ? | ? |