Created
June 20, 2020 01:49
-
-
Save JacobHsu/22cf7d9c338680145c835f713ab49b0d to your computer and use it in GitHub Desktop.
promise1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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