// Hypothetical underlying implementation for illustration
class Promise {
static get [Symbol.species]() {
return this;
}
}Promise[Symbol.species] / notebook
Promise[Symbol.species]
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
class SubPromise extends Promise {}
SubPromise[Symbol.species] === SubPromise; // truePromise[Symbol.species]; // [Function: Promise]class MyPromise extends Promise {
// Override MyPromise species to the parent Promise constructor
static get [Symbol.species]() {
return Promise;
}
}class MyPromise extends Promise {
someValue = 1;
}
console.log(MyPromise.resolve(1).then(() => {}).someValue); // 1class MyPromise extends Promise {
someValue = 1;
static get [Symbol.species]() {
return Promise;
}
}
console.log(MyPromise.resolve(1).then(() => {}).someValue); // undefined