function func(cb) {
setTimeout(()=>{
cb & cb();
}, 1000)
}
func(()=> {
console.log(1);
func(()=>{
console.log(2);
func(()=>{
console.log(3);
func(()=>{
console.log(4)
})
})
})
})
function fun2() {
return new Promise ((resolve, reject)=> {
setTimeout(()=> {
resolve();},1000)
}
}
fun2.then(()=> {
console.log(10);
return func2();
}).then(()=>{
console.log(20);
return func2();
}).then(()=>{
console.log(30);
return func2();
}).then(()=>{
console.log(40)
})
网友评论