首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

TypedArray.@@species

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

语法

代码语言:javascript
复制
TypedArray[Symbol.species]

where TypedArray is one of:

Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array

描述

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

示例

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

代码语言:javascript
复制
Int8Array[Symbol.species];    // function Int8Array()
Uint8Array[Symbol.species];   // function Uint8Array()
Float32Array[Symbol.species]; // function Float32Array()

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

代码语言:javascript
复制
class MyTypedArray extends Uint8Array {
  // Overwrite MyTypedArray species to the parent Uint8Array constructor
  static get [Symbol.species]() { return Uint8Array; }
}

规范

Specification

Status

Comment

ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'get %TypedArray% @@species ' in that specification.

Standard

Initial definition.

ECMAScript Latest Draft (ECMA-262)The definition of 'get %TypedArray% @@species ' in that specification.

Draft

?

浏览器兼容性

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)

?

?

?

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com