非常教程

JavaScript参考手册

TypedArray

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; }
}

规范

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)

?

?

?

JavaScript

JavaScript 是一种高级编程语言,通过解释执行,是一门动态类型,面向对象(基于原型)的解释型语言。它已经由ECMA(欧洲电脑制造商协会)通过 ECMAScript 实现语言的标准化。它被世界上的绝大多数网站所使用,也被世界主流浏览器( Chrome、IE、FireFox、Safari、Opera )支持。JavaScript 是一门基于原型、函数先行的语言,是一门多范式的语言,它支持面向对象编程,命令式编程,以及函数式编程。它提供语法来操控文本、数组、日期以及正则表达式等,不支持 I/O,比如网络