Quiz

  1. can you explain why methods are functions?

    Sure. A method is just a function that belongs to a particular class of object.

  2. what value is assigned to is when the normal functions change it?

    if they are called like methods, the object

    if they are called as normal functions, the global object

  3. Could we revisit the idea of an "ordinary" function again? How come that would have the wrong value for "this"?

    Because it gets assigned to the global object, which is (almost) never what we want.

  4. What has the value of "this" changed into in the example of "hat.map(ron.deposit);"?

    The global object, so the code this.balance += amt ends up incrementing a non-existent global variable.

  5. can you explain more on how
    depositAll (hat) {
            hat.map(function (amt) { this.deposit(amt) });
        }
    
    this function works? thanks!

    Well, of course, it doesn't work: Because the anonymous function is called as an ordinary function, so this is the global object, and so this.deposit doesn't exist.

    But an arrow function would work.