Answer the question
In order to leave comments, you need to log in
How does executor work in new Promise?
Good evening. I got a little unusual code for me, where the syntax is actively used
new Promise(executor => {
if (....) {
....;
executor();
return;
} else if (....) {
....;
....;
executor();
}
if (....) {
....;
....;
executor()
return()
}
})
Answer the question
In order to leave comments, you need to log in
a function is passed to new Promise (in this case, an arrow function).
It has two parameters - a function for resolve and a function for reject.
In this case, the second parameter is not specified (reject is not used here), and the first one is named executor. And in the right places of our arrow function, the executor function is called to resolve the promise. In a more familiar code, it would be called resolve or res, but in general, you can call this parameter whatever you like, the main thing is that it should go first in the list
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question