javascript - Why does the following promise return this value?
漂亮男人
漂亮男人 2017-05-16 13:30:47
0
2
569
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'

after timeout is executed?
漂亮男人
漂亮男人

reply all(2)
小葫芦

https://developer.mozilla.org...

The ability to pass extra parameters to the delay function

某草草

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

setTimeout(function () {
    resolve('done')
}, ms)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template