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 orundefined
throughresolve()
andreject()
to.then
and.catch
. The values themselves aren't being passed to.then
or.catch
, rather they're being passed to thefunctionscalled by.then
or.catch
.
08 Quiz: Write Your First Promise
Instructions
- Download
setTimeout-start.zip
from the Supporting Materials Section. - Wrap
setTimeout
in 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.zip
in the Supporting Materials Section to see my code!
09 Quiz: Wrapping readyState
Instructions
- Download
readyState-start.zip
in 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
readystatechange
in a Promise. - If
document.readyState
is not'loading'
,resolve()
. - Test by chaining
wrapperResolved()
. If all goes well, you should see "Resolved" on the page!