doc: add pizza example
This commit is contained in:
1 parent
ed97c2fcbe
commit
62a3f7eb14
1 file changed
+26
-1
@@ -170,4 +170,29 @@ function executionFn(resolve, reject) { //回调作为一个参数
|
||||
}
|
||||
```
|
||||
你可以定义这个函数并将其传递给Promise构造函数
|
||||
使用then和catch在Promise对象上串联动作
|
||||
使用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); });
|
||||
```
|
||||
Reference in new issue
Block a user