JavaScript get ArrayBuffer[@@species]

🌙
手机阅读
本文目录结构

该 **ArrayBuffer[@@species]** 访问器属性会返回 ArrayBuffer 构造器。

语法

ArrayBuffer[Symbol.species]

描述

这个 species 访问器属性会返回默认的 ArrayBuffer 构造器。子类构造器可能会覆盖它以改变构造器赋值。

示例

返回默认的 ArrayBuffer 构造器:

ArrayBuffer[Symbol.species]; // function ArrayBuffer()

在派生集合对象中(比如你定制的 array buffer MyArrayBuffer),MyArrayBuffer species 就是 MyArrayBuffer 构造器。但是,你可能想要在派生类里重写它,以期返回的是父类的 ArrayBuffer 对象:

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

规范

Specification Status Comment
[ECMAScript 2015 (6th Edition, ECMA-262)
get ArrayBuffer [ @@species ]](https://www.ecma-international.org/ecma-262/6.0/#sec-get-arraybuffer-@@species) Standard Initial definition.
[ECMAScript Latest Draft (ECMA-262)
get ArrayBuffer [ @@species ]](https://tc39.es/ecma262/#sec-get-arraybuffer-@@species) Draft  

浏览器支持

The compatibility table on this page is generated from structured data. If you’d like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

Update compatibility data on GitHub

Desktop Mobile Server
Chrome Edge Firefox
@@species Chrome ? Edge Full support 13 Firefox Full support 48
Full support 6.5.0

Full support 6.0.0

Disabled

Disabled From version 6.0.0: this feature is behind the --harmony runtime flag.

|

Legend

Full support  

Full support

Compatibility unknown  

Compatibility unknown

User must explicitly enable this feature.

User must explicitly enable this feature.

相关

AXIHE / 精选资源

浏览全部教程

面试题

学习网站

前端培训
自己甄别

前端书籍

关于朱安邦

我叫 朱安邦,阿西河的站长,在杭州。

以前是一名平面设计师,后来开始接接触前端开发,主要研究前端技术中的JS方向。

业余时间我喜欢分享和交流自己的技术,欢迎大家关注我的 Bilibili

关注我: Github / 知乎

于2021年离开前端领域,目前重心放在研究区块链上面了

我叫朱安邦,阿西河的站长

目前在杭州从事区块链周边的开发工作,机械专业,以前从事平面设计工作。

2014年底脱产在老家自学6个月的前端技术,自学期间几乎从未出过家门,最终找到了满意的前端工作。更多>

于2021年离开前端领域,目前从事区块链方面工作了