Last active
March 20, 2020 03:11
-
-
Save kkeeth/2bbddaaf5d0980287605dff03e2b444d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// then-catch-final(then) | |
const taskA = () => { | |
console.log("Task A") | |
throw new Error("throw Error at taskA") | |
} | |
const taskB = () => { | |
console.log("Task B") // does not be call | |
} | |
const onRejected = (error) => { | |
console.error(error) // => "throw Error at taskA" | |
} | |
const finalTask = () => { | |
console.log("Final Task") | |
} | |
Promise.resolve() | |
.then(taskA) | |
.then(taskB) | |
.catch(onRejected) | |
.then(finalTask) | |
// onload or dom content loaded | |
const onReady = () => { | |
return new Promise((resolve) => { | |
const readyState = document.readyState | |
if ( | |
readyState === "interactive" || | |
readyState === "complete" | |
) { | |
resolve() | |
} else { | |
window.addEventListener("DOMContentLoaded", resolve) | |
} | |
}) | |
} | |
onReady().then(() => { | |
console.log("DOM fully loaded and parsed") | |
}) | |
console.log("==Starting==") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment