美文网首页
ES6-promise

ES6-promise

作者: 柒轩轩轩轩 | 来源:发表于2019-10-23 04:56 被阅读0次
    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)
    })
    

    相关文章

      网友评论

          本文标题:ES6-promise

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