I want to learn more thoroughly how promises work in JavaScript and trying the next code:
function delay(timeout) {
return new Promise(function(resolve, reject){
setTimeout(resolve,timeout);
});
}
var promise = delay(10000);
promise.then(alert('after delay'));
I wanted to write a wrapper for JS setTimeout() function and I assume alert appearing after 10 sec while executing this code but it shows immediately, could someone explain what is wrong here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…