I’m struggling to remember how to do method-chaining with Node.js.
Here’s a minimum-viable-example for a promise-then to convert to an anonymous function.
I got this code from the MDN Promise.prototype.then() doc. This does return success.
const promise1 = new Promise((resolve, reject) => {
resolve('Success!');
});
promise1.then((value) => {
console.log(value);
// Expected output: "Success!"
});
But when I try to convert this to an anonymous function, I get Error: (intermediate value).then is not a function
. I’ve tried async
and changing around my bracketing but I cannot seem to jog my memory on how to set this up any more.
(
//async
(resolve, reject) => {
resolve('Success!');
}).then((value) => {
console.log(value);
// Expected output: "Success!"
});
How can you make anonymous method-chaining?