• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • get TypedArray[@@species]

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

    上篇:TypedArray

    下篇:TypedArray.name