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

【js】Promise构造函数是同步执行还是异步执行,那么then方法呢? #42

Open
misty0304 opened this issue Feb 27, 2020 · 1 comment

Comments

@misty0304
Copy link
Owner

【js】Promise构造函数是同步执行还是异步执行,那么then方法呢?

@misty0304
Copy link
Owner Author

misty0304 commented Feb 27, 2020

const promise = new Promise((resolve, reject) => {
console.log(1);
resolve(5);
console.log(2);
}).then(val => {
console.log(val);
});

promise.then(() => {
console.log(3);
});

console.log(4);

setTimeout(function() {
console.log(6);
});

执行结果: 124536
promise构造函数是同步执行的,then方法是异步执行的

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