oliver1204 / randomNotes

用来记录平时的日常总结
1 stars 0 forks source link

promise 还有疑点 #70

Closed oliver1204 closed 5 years ago

oliver1204 commented 6 years ago

输出下列结果:

promise()
.then(() => {
  console.log('1')
})
.then(() => {
  console.log('2')
})
.catch(() => {
  console.log('3')
})
.then(() => {
  console.log('4')
})

实现方式:

function one(resolve, reject){
    console.log('1');
    setTimeout(()=>{
        reject('3');
    }, 2000);

}

function two(clothes){
    console.log('2');
    setTimeout(()=>{
        console.log('4');
    }, 3000);
}

new Promise(one)
.catch(two())

promise 解析