promise

作者: BergHuang | 来源:发表于2018-02-09 15:37 被阅读0次

let foo = () => new Promise((resolve, reject) => {

  let canResolve = true;

  if (canResolve) {

    resolve('Resolved');

  } else {

    reject('failed');

  }

})

foo().then(data => console.log(data), reason => console.log(reason));

resolve将在promise主体执行完后调用then的第一个callback,reject调用第二个.

相关文章

网友评论

      本文标题:promise

      本文链接:https://www.haomeiwen.com/subject/sdoftftx.html