SOURCE

Promise.race = function(args) {
    return new Promise((resolve, reject) => {
        for (let item of args) {
            Promise.resolve(item).then(res => {
                resolve(res);
            }, error => {
                reject(error);
            });
        }
    });
}

Promise.race([Promise.resolve(2), Promise.reject(1)]).then(res => {
    console.log(res);
}, error => {
    console.log(error);
});
console 命令行工具 X clear

                    
>
console