Lecture List
02 Callbacks vs Promises
03 Callbacks vs Thens
04 Course Map
05 Promise Timeline
06 Quiz: Async Scenarios
07 Syntax
Cam says: whoops, I don't actually have a good link for you at the moment. However, I can explain a little further. Try running this code in your browser.
new Promise(function(resolve) {
console.log('first');
resolve();
console.log('second');
}).then(function() {
console.log('third');
});
You'll notice that'first','second'and'third'all get logged. Most notably,'second'gets logged despite the fact that it comes afterresolve().
Around 2:11, I start talking about passing values orundefinedthroughresolve()andreject()to.thenand.catch. The values themselves aren't being passed to.thenor.catch, rather they're being passed to thefunctionscalled by.thenor.catch.
08 Quiz: Write Your First Promise
Instructions
- Download
setTimeout-start.zipfrom the Supporting Materials Section. - Wrap
setTimeoutin a Promise inside thewait()function.resolve()in setTimeout's callback. console.log(this)inside the Promise and observe the results.- Make sure
wait()returns the Promise too!
Check outsetTimeout-solution.zipin the Supporting Materials Section to see my code!
09 Quiz: Wrapping readyState
Instructions
- Download
readyState-start.zipin the downloadables section. - Set network throttling so that the page isn't ready instantly. (Also, it's generally a good practice to have some throttling when testing sites. It'll help you see your site's performance from your users' perspectives.)
- Wrap an event listener for
readystatechangein a Promise. - If
document.readyStateis not'loading',resolve(). - Test by chaining
wrapperResolved(). If all goes well, you should see "Resolved" on the page!