here is a code example:
var promise = new Promise((resolve, reject) => {
resolve("resolved");
});
promise.abort = function () {
console.log("abort!");
};
console.log(promise.abort());
function bar() {
return promise.then((value) => {
return value + "!";
});
}
newPromise = bar();
newPromise.then(value => {
console.log(value);
})
console.log(newPromise.abort());
i added a custom function to a promise. call the function abort()
works like expected.
in the function bar()
i use the then()
method to log out the resolved value.
i know that the return value of bar()
is a new promise. but it loses the custom function abort()
.
how can i inheritance the custom function to the new promise?