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

  1. Download setTimeout-start.zip from the Supporting Materials Section.
  2. Wrap setTimeout in a Promise inside the wait() function. resolve() in setTimeout's callback.
  3. console.log(this) inside the Promise and observe the results.
  4. Make sure wait() returns the Promise too!

Check outsetTimeout-solution.zipin the Supporting Materials Section to see my code!

09 Quiz: Wrapping readyState

Instructions

  1. Download readyState-start.zip in the downloadables section.
  2. 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.)
  3. Wrap an event listener for readystatechange in a Promise.
  4. If document.readyState is not 'loading', resolve().
  5. Test by chaining wrapperResolved(). If all goes well, you should see "Resolved" on the page!

More on document.readyState

results matching ""

    No results matching ""