Skip to content

Commit

Permalink
fix:promise article enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
angryreid committed Aug 29, 2021
1 parent 8c118e6 commit bfb49a6
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions docs/JavaScript/模拟实现promise.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- 设定三个状态 `PENDING、FULFILLED、REJECTED` ,只能由`PENDING`改变为`FULFILLED、REJECTED`,并且只能改变一次
- `MyPromise`接收一个函数`executor``executor`有两个参数`resolve`方法和`reject`方法
- `resolve``PENDING`改变为`FULFILLED`
- `reject``PENDING`改变为`FULFILLED`
- `reject``PENDING`改变为`REJECTED`
- `promise`变为`FULFILLED`状态后具有一个唯一的`value`
- `promise`变为`REJECTED`状态后具有一个唯一的`reason`

Expand Down Expand Up @@ -93,7 +93,7 @@
onFulfilled(this.value);
break;
case REJECTED:
onFulfilled(this.value);
onRejected(this.value);
break;
case PENDING:
this.onFulfilledCallbacks.push(() => {
Expand Down Expand Up @@ -269,7 +269,7 @@ MyPromise.prototype.finally = function(fn) {
`Promise.resolve`用来生成一个直接处于`FULFILLED`状态的Promise。

```js
MyPromise.reject = function(value) {
MyPromise.resolve = function(value) {
return new MyPromise((resolve, reject) => {
resolve(value);
});
Expand All @@ -295,7 +295,7 @@ MyPromise.reject = function(reason) {

```js
MyPromise.all = function (promises) {
return new Promise((resolve, reject) => {
return new MyPromise((resolve, reject) => {
if (promises.length === 0) {
resolve([]);
} else {
Expand Down Expand Up @@ -325,11 +325,10 @@ MyPromise.reject = function(reason) {

```js
MyPromise.race = function (promises) {
return new Promise((resolve, reject) => {
return new MyPromise((resolve, reject) => {
if (promises.length === 0) {
resolve();
} else {
let index = 0;
for (let i = 0; i < promises.length; i++) {
promises[i].then(data => {
resolve(data);
Expand Down

0 comments on commit bfb49a6

Please sign in to comment.