-
reduce queue
查看全部 -
forEach queue
查看全部 -
map promise array
查看全部 -
promiseAll
error
查看全部 -
first reject error
all resolve values
查看全部 -
catch 只是 then 的语法糖,本质上与 then 没有什么不同!?
查看全部 -
reject error
===
catch error语法糖
查看全部 -
```js "use strict"; /** * * @author xgqfrms * @license MIT * @copyright xgqfrms * @created 2020-10-01 * @modified * * @description * @difficulty Easy Medium Hard * @complexity O(n) * @augments * @example * @link * @solutions * * @best_solutions * */ const log = console.log; const promise = new Promise((resolve, reject) =>{ log(1); resolve(1); }); // then((json) => log(3, json), (err) => log(err)); promise .then((v) => { // not new Promise ⚠️ // return new Promise((ok, err) => { new Promise((ok, err) => { log(2); log(`v =`, v); // resolve callback, ok ok(`✅`); // reject callback, err err(`❌`) }).then((v) => { log(3); log(`v =`, v, `\n`); return v; }).then((v) => { log(4); log(`v =`, v, `\n`); return v; }); // 遇到 Promise 立即执行,Promise 后面紧跟着的第一个 then 也马上执行,后面的 then 按照 Promise 创建的先后顺序,依次执行 then! return v; }) .then((v) => { log(5); log(`v =`, v); return v; }) .then((v) => { log(6); log(`v =`, v); return v; }); /* 1 2 v = 1 3 v = ✅ 5 v = 1 4 v = ✅ 6 v = 1 */ ```
查看全部 -
ignore then ???
查看全部 -
```js
"use strict";
/**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
* @created 2020-10-01
* @modified
*
* @description
* @difficulty Easy Medium Hard
* @complexity O(n)
* @augments
* @example
* @link
* @solutions
*
* @best_solutions
*
*/
const log = console.log;
const promise = new Promise((resolve, reject) =>{
log(1);
resolve(1);
});
// then((json) => log(3, json), (err) => log(err));
promise
.then((v) => {
// not new Promise ⚠️
// return new Promise((ok, err) => {
new Promise((ok, err) => {
log(2);
log(`v =`, v);
// resolve callback, ok
ok(`✅`);
// reject callback, err
err(`❌`)
}).then((v) => {
log(3);
log(`v =`, v, `\n`);
return v;
}).then((v) => {
log(4);
log(`v =`, v, `\n`);
return v;
});
// 遇到 Promise 立即执行,Promise 后面紧跟着的第一个 then 也马上执行,后面的 then 按照 Promise 创建的先后顺序,依次执行 then!
return v;
})
.then((v) => {
log(5);
log(`v =`, v);
return v;
})
.then((v) => {
log(6);
log(`v =`, v);
return v;
});
/*
1
2
v = 1
3
v = ✅
5
v = 1
4
v = ✅
6
v = 1
*/
```
查看全部 -
return new promise
查看全部 -
promise 嵌套
查看全部 -
then
return
no return
查看全部 -
return new Promise
Async/Await
查看全部 -
模拟 ajax 异步请求
查看全部
举报