Answer the question
In order to leave comments, you need to log in
How to call a function that returns a Promise inside that Promise's handler?
According to my logic (apparently incorrect), this code should be analogous to an infinite loop that outputs 22, 23, 24, and so on. But it only outputs 22 once. What is the reason?
function find() {
let numberPage = 22;
getPromiseOpenPage(numberPage);
function getPromiseOpenPage (numberPage) {
return new Promise( function (resolve, reject) {
resolve(numberPage);
})
}
getPromiseOpenPage().then(
function (res) {
console.log(res);
getPromiseOpenPage(res++);
}
)
}
Answer the question
In order to leave comments, you need to log in
function find(start) {
function iteration(number) {
new Promise(function(resolve, reject) {
resolve(number++)
}).then(function() {
console.log(number)
if (number < 100) iteration(number)
})
}
iteration(start)
}
find(22)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question