Quiz

  1. Could you review what an arrow function is and how it's structured?

    We learned about those way back at the beginning: arrow functions

    Then we learned about them again in the context of the this keyword: arrow functions and this.

    The MDN reference page

    In a nutshell:

    
        f = x => 2*x;
        f(1) // evaluates to 2
    
        g = (x,y) => 2*x+y;
        g(1,2) // evaluates to 4
    
        h = (x,y) => { if(x>y) { return x/2 } else { return y*2 }
        h(3,4) // evaluates to 8
    
    
    1. In simple cases, you can omit braces and return and parens around the one parameter
    2. If you have multiple parameters, use parens
    3. If you have a block of code, use braces and return
    4. Arrow functions don't bind this, which is crucial inside methods
  2. Could you explain a bit more about how/when the URL changes?

    Could you explain more / give an example of what you mean by " without the appended stuff, the same .get returns all the data in the store"?

    For sure. I've combined these questions, because I think they are both about this section: The Get method.

    I also discovered an editing error in this section adjustments in main

    The backend server provides a basic URL: https://cs.wellesley.edu/cs204cloud/coffeerun/

    That URL can be used in two ways:

    • https://cs.wellesley.edu/cs204cloud/coffeerun/ which returns all the orders (for the coffeerun user), and
    • https://cs.wellesley.edu/cs204cloud/coffeerun/scott@wellesley.edu which returns one order, the one matching that email address, if any

    This is a common convention in web databases called a REST API, where the basic url, say /items/ refers to the whole collection and /items/123 which refers to the item with that ID.

  3. After we used get() function to get the data from the server, could we store the data somewhere local so we can call from local if we want to process it more in the future outside of callback?

    Yes! That's a great idea. Like the caching idea we discussed last time.

    But you can't use that idea to get around the idea of callbacks. You can't do:

    
        let data = null;
        $.get('/some/url', (response) => { data = response; } );
        console.log(data);  // still null, fetch hasn't completed yet
    
    

    But eventually, the data will be there and you can use it.