SOURCE

// promise形式的定时器
function timeout(ms) {
    return new Promise((resolve, reject) => {
        setTimeout(resolve, ms, "done");
    });
}
// 永远返回reject的promise
function alwaysReject(ms) {
    return new Promise((resolve, reject) => {
        setTimeout(function () {
            let random = Math.floor(Math.random() * 1000);
            console.log("success" + random);
            reject(random);
        }, 1000);
    });
}

console.log('alwaysReject start');
alwaysReject(1)
    .then(
        () => {
            console.log(`then1_solve`);
            return alwaysReject(2);
        },
        () => {
            console.log(`then1_reject`);
            return "adas";
        }
    )
    .then(
        () => {
            console.log(`then2_solve`);
            return alwaysReject(3);
        })
    .then(() => {
        console.log(`then3_solve`);
        return alwaysReject(4);
    })
    .catch(error => {
        console.log(`catch`);
    });
console 命令行工具 X clear

                    
>
console