From 53389645e7790b0d5009d9e6fa32fe31246e56d6 Mon Sep 17 00:00:00 2001 From: ruanyf Date: Thu, 1 Mar 2018 13:30:46 +0800 Subject: [PATCH] docs(promise): edit promise --- docs/promise.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/promise.md b/docs/promise.md index 4793c58..15b1ca7 100644 --- a/docs/promise.md +++ b/docs/promise.md @@ -681,8 +681,10 @@ const p = Promise.race([ setTimeout(() => reject(new Error('request timeout')), 5000) }) ]); -p.then(response => console.log(response)); -p.catch(error => console.log(error)); + +p +.then(console.log) +.catch(console.error); ``` 上面代码中,如果 5 秒之内`fetch`方法无法返回结果,变量`p`的状态就会变为`rejected`,从而触发`catch`方法指定的回调函数。