Skip to content

Instantly share code, notes, and snippets.

@JacobHsu
Created June 20, 2020 01:49
Show Gist options
  • Save JacobHsu/22cf7d9c338680145c835f713ab49b0d to your computer and use it in GitHub Desktop.
Save JacobHsu/22cf7d9c338680145c835f713ab49b0d to your computer and use it in GitHub Desktop.
promise1
const promise = new Promise((resolve, reject) => {
console.log(1);
resolve();
console.log(2);
reject('error');
})
promise.then(() => {
console.log(3);
}).catch(e => console.log(e))
console.log(4);
// 1 2 4 3
// promise構造函數的代碼會立即執行,then或者reject裡面的代碼會放入異步微任務隊列,在宏任務結束後會立即執行
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment