SharedArrayBuffer[Symbol.species]

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since December 2021.

The SharedArrayBuffer[Symbol.species] static accessor property returns the constructor used to construct return values from SharedArrayBuffer methods.

Warning: The existence of [Symbol.species] allows execution of arbitrary code and may create security vulnerabilities. It also makes certain optimizations much harder. Engine implementers are investigating whether to remove this feature. Avoid relying on it if possible.

Syntax

js
SharedArrayBuffer[Symbol.species]

Return value

The value of the constructor (this) on which get [Symbol.species] was called. The return value is used to construct return values from array buffer methods that create new array buffer.

Description

The [Symbol.species] accessor property returns the default constructor for SharedArrayBuffer objects. Subclass constructors may override it to change the constructor assignment. The default implementation is basically:

js
// Hypothetical underlying implementation for illustration
class SharedArrayBuffer {
  static get [Symbol.species]() {
    return this;
  }
}

Because of this polymorphic implementation, [Symbol.species] of derived subclasses would also return the constructor itself by default.

js
class SubArrayBuffer extends SharedArrayBuffer {}
SubArrayBuffer[Symbol.species] === SubArrayBuffer; // true

When calling array buffer methods that do not mutate the existing array but return a new array buffer instance (for example, slice()), the array's constructor[Symbol.species] will be accessed. The returned constructor will be used to construct the return value of the array buffer method.

Examples

Species in ordinary objects

The [Symbol.species] property returns the default constructor function, which is the SharedArrayBuffer constructor for SharedArrayBuffer.

js
SharedArrayBuffer[Symbol.species]; // function SharedArrayBuffer()

Species in derived objects

In an instance of a custom SharedArrayBuffer subclass, such as MySharedArrayBuffer, the MySharedArrayBuffer species is the MySharedArrayBuffer constructor. However, you might want to overwrite this, in order to return parent SharedArrayBuffer objects in your derived class methods:

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

Specifications

Specification
ECMAScript® 2027 Language Specification
# sec-sharedarraybuffer-%symbol.species%

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
[Symbol.species]
Chrome – Full support
Chrome 68 (Release date: 2018-07-24)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 79 (Release date: 2020-07-28)
footnote Full support
Opera – Full support
Opera 55 (Release date: 2018-08-16)
footnote Full support
Safari – Full support
Safari 15.2 (Release date: 2021-12-13)
footnote Full support
Chrome Android – Full support
Chrome Android 89 (Release date: 2021-03-02)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 63 (Release date: 2021-04-16)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15.2 (Release date: 2021-12-13)
footnote Full support
Samsung Internet – Full support
Samsung Internet 15 (Release date: 2021-08-13)
footnote Full support
WebView Android – No support
WebView Android
footnote No support
WebView on iOS – Full support
WebView on iOS 15.2 (Release date: 2021-12-13)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1 (Release date: 2020-05-13)
footnote Full support
Node.js – Full support
Node.js 8.10 (Release date: 2018-03-06)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

See also