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

异步编程: Promise 题目 1 - 6 #116

Open
leslie1943 opened this issue Jan 3, 2021 · 0 comments
Open

异步编程: Promise 题目 1 - 6 #116

leslie1943 opened this issue Jan 3, 2021 · 0 comments

Comments

@leslie1943
Copy link
Owner

Promise 题目 1 - 6

  • 如果把fn的调用放到start之后呢?
const fn = () =>
  new Promise((resolve, reject) => {
    console.log(1);
    resolve("success");
  });
console.log("start");
fn().then(res => {
  console.log(res);
});
// start, 1, success

过程分析

  • 是的, 现在 start 就在 1 之前打印出来了,因为 fn 函数是之后执行的.
  • 注意⚠️: 之前我们很容易就以为看到 new Promise() 就执行它的第一个参数函数了, 其实这是不对的, 就像这两道题中, 我们得注意它是不是被包裹在函数当中, 如果是的话, 只有在函数调用的时候才会执行.
@leslie1943 leslie1943 changed the title ### Promise 题目 1 - 6 异步编程: Promise 题目 1 - 6 Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant