promise学习---中断promise链(then回调链)

中断 promise 链   (1) 当使用 promise 的 then 链式调用时, 在中间中断, 不再调用后面的回调函数   (2) 办法: 在回调函数中返回一个 pendding 状态的 promise 对象  
        let p = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve('OK');
            }, 1000);
        });

        p.then(value => {
            console.log(111);
            //有且只有一个方式 如下
            return new Promise(() => {});
        }).then(value => {
            console.log(222);
        }).then(value => {
            console.log(333);
        }).catch(reason => {
            console.warn(reason);
        });

 

上一篇:ES6学习---Promise对象catch方法


下一篇:ES6特性 -- Promise特性