Skip to main content
Version: 3.27.2

get ArrayBuffer[Symbol.species]

The ArrayBuffer[Symbol.species] accessor property returns the constructor used to construct return values from array buffer 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

ArrayBuffer[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 buffers.

Description

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

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

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

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

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