markdown 承诺

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 承诺相关的知识,希望对你有一定的参考价值。

const obj = {
  isTrue: true,
  isFalse: false
}

const secondPromise = finalMsg => {
  const final = `${finalMsg} in the second promise`;
  return Promise.resolve(final);
}

const promise = new Promise((resolve, reject) => {
  const { isTrue, isFalse } = obj;
  if (isTrue) {
    const message = `This is ${isTrue}`;
    resolve(message);
  } else {
    const message = `This is ${isFalse}`;
    reject(message);
  }
})

promise.then(secondPromise).then(success => {
  console.log("Success", success)
}).catch(error => {
  console.log("Error", error)
})
## Promises

What is a promise?

1. An object that may produce a single value in the future
    1. Either a resolved value
    2. Or a reason why it was not resolved
  
2. Three states
    1. Pending
    2. Fulfilled
    3. Rejected

3. The ES6 Promise constructor takes a function, which takes in two parameters:
    1. ```resolve()```
    2. ```reject()```

以上是关于markdown 承诺的主要内容,如果未能解决你的问题,请参考以下文章

markdown JS中的eventproxy和承诺

markdown JS承诺

markdown JS承诺

markdown JS承诺

markdown 承诺和交付(也是未来)

markdown 挑战04:承诺