> For the complete documentation index, see [llms.txt](https://bvct1742.gitbook.io/one-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bvct1742.gitbook.io/one-book/knowledge/js/promise.race-shi-xian-yuan-li.md).

# Promise.race 实现原理

```javascript
Promise.prototype.race = function(promises) {
    return new Promise((resolve, reject) => {
        if (!isArray(promises)) {
            return reject(new TypeError('Arguments not Array'));
        }
        for (let p of promises) {
            Promise.resolve(p).then(
                res => resolve(res), 
                rej => reject(rej)
            )
        }
    })
}
```
