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

假如有这么一段代码 #318

Closed
huaipomen opened this issue Nov 15, 2019 · 1 comment
Closed

假如有这么一段代码 #318

huaipomen opened this issue Nov 15, 2019 · 1 comment

Comments

@huaipomen
Copy link

假如有这么一段代码

new Promise(resolve => {
    resolve(1);
    Promise.resolve().then(() => console.log(2));
    Promise.resolve().then(() => console.log(5));
}).then(t => console.log(t));

请问为什么输出结果是2,5,1呢?
resolve(1) 之后,不应该是优先注册了外部 .then 的回调吗?
还是说内部的 Promise 是同步执行的?

Originally posted by @ftv031 in #19 (comment)

resolve 只是把改变了Promise的status 然后把1存起来了 并不是直接执行then , 而是then之后看到状态是resolved才直接执行

@libin1991
Copy link

promise需要将里面的代码都执行完才会到自己的then

 resolve(1);
    Promise.resolve().then(() => console.log(2));
    Promise.resolve().then(() => console.log(5));

@yygmind yygmind closed this as completed Nov 21, 2019
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

3 participants