From 65e9a0b13baa2f19b298c1aba0fd41ff84fb0a39 Mon Sep 17 00:00:00 2001 From: Leon Xu <6479451-leonxu260@users.noreply.gitlab.com> Date: Sun, 17 Oct 2021 17:00:25 -0700 Subject: [PATCH] doc: create rejecting a pizza section --- source/_posts/异步JavaScript.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/source/_posts/异步JavaScript.md b/source/_posts/异步JavaScript.md index aa6bf05..12c5846 100644 --- a/source/_posts/异步JavaScript.md +++ b/source/_posts/异步JavaScript.md @@ -224,3 +224,18 @@ let orderPizza = new Promise(orderExecutor); orderPizza.then(function (value) { console.log(value); }); console.log("Waiting for my pizza!"); ``` + +# 拒绝一个披萨 +```javascript +function orderExecutor(resolve, reject) { + console.log('Pizza ordered...'); + setTimeout(function() { + reject("Ran out of cheese. Can you believe it?"); + }, 2000) +} + +let orderPizza = new Promise(orderExecutor); +orderPizza + .then(function () { console.log("Woohoo, let's eat!"); }) + .catch(function (value) { console.log(value); }); +``` \ No newline at end of file