diff --git a/source/_posts/异步JavaScript.md b/source/_posts/异步JavaScript.md index 7dc01dd..c097826 100644 --- a/source/_posts/异步JavaScript.md +++ b/source/_posts/异步JavaScript.md @@ -170,4 +170,29 @@ function executionFn(resolve, reject) { //回调作为一个参数 } ``` 你可以定义这个函数并将其传递给Promise构造函数 -使用then和catch在Promise对象上串联动作 \ No newline at end of file +使用then和catch在Promise对象上串联动作 + +# 披萨例子 +我们可以传递一个值来解析。。。 +```javascript +function orderExecutor(resolve, reject) { + console.log('making our pizza...'); + setTimeout(function () { + resolve("Here's your pizza!"); + }, 5000); +} + +let orderPizza = new Promise (orderExecutor); +orderPizza.then(function (value) { console.log(value); }); +``` +这个值传递给then函数 +传递给then的函数可以将值传递给下一个then回调函数。 + +```javascript +function eat(value) { + return value + ", and now it's gone"; +} + +let orderPizza = new Promise (orderExecutor); +orderPizza.then(eat).then(function (value) { console.log(value); }); +``` \ No newline at end of file