function timeout(ms) {
return new Promise((resolve, reject) => {
setTimeout(resolve, ms, 'done');
});
}
timeout(100).then((value) => {
console.log(value);
});
Excuse me why 'done'
is returned. Doesn't setTimeout only have two parameters? Why does resolve get 'done'
https://developer.mozilla.org...
setTimeout The first parameter is the callback function, the second is the time to delay the callback, and after the third parameter is the parameter of the callback function. The way you write it is equivalent to