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 #151

Open
smileyby opened this issue Sep 10, 2021 · 3 comments
Open

测试题:Promise #151

smileyby opened this issue Sep 10, 2021 · 3 comments
Labels

Comments

@smileyby
Copy link
Owner

setTimeout(()=>{console.log(1)},0)
async function timeout (){
const a = await new Promise((res, rej) => {
setTimeout(() => {console.log(2); res(3)}, 0)
})
console.log(a);
}
await timeout();
console.log(4);

@smileyby smileyby added the 测试题 💫 测试题 label Sep 10, 2021
@smileyby
Copy link
Owner Author

setTimeout(()=>{
console.log(0)
}, 0);
new Promise((resolve, reject) => {
console.log(1);
resolve()
}).then(()=>{
console.log(2);
new Promise((resolve, reject) => {
console.log(3);
resolve();
}).then(() => {
console.log(4)
}).then(() => {
console.log(5)
})
}).then(() => {
console.log(6)
})

new Promise((resolve, reject) => {
console.log(7);
resolve();
}).then(() => {
console.log(8);
})

@smileyby
Copy link
Owner Author

@smileyby
Copy link
Owner Author

Promise.prototype.then 方法,当未传入参数,或者参数非函数时,会被忽略掉且不会报错,当Promise状态发生改变的时候 then方法会将最后一次状态作为then的状态被执行

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant