Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

51. 什么是promise #68

Open
webVueBlog opened this issue Jun 9, 2022 · 0 comments
Open

51. 什么是promise #68

webVueBlog opened this issue Jun 9, 2022 · 0 comments

Comments

@webVueBlog
Copy link
Owner

Promise 是一个对象,它可能在未来某个时间产生单个值,具有已解决的值或未解决的原因(例如,网络错误)。它将处于 3 种可能的状态之一:已完成、已拒绝或待处理。

Promise 创建的语法如下所示,

const promise = new Promise(function (resolve, reject) {
  // promise description
});

承诺的用法如下,

const promise = new Promise(
  (resolve) => {
    setTimeout(() => {
      resolve("I'm a Promise!");
    }, 5000);
  },
  (reject) => {}
);

promise.then((value) => console.log(value));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant