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:
// 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.
class SubArrayBuffer extends SharedArrayBuffer {}
SubArrayBuffer[Symbol.species] === SharedArrayBuffer; // 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.