• Could you explain the map question on quiz14b?

    Sure. That question asks why the following fails:

    
    hat.map(ron.deposit);
    
    

    It fails because the deposit function is pulled out of the ron object (which in fact gets it from the Account.prototype) and that function is:

    
    function (amt) { this.balance += amt; }
    
    

    But the keyword this is not bound to ron or, in fact, any bank account.

    So, the value of this is incorrect (has the wrong value).

  • Can you explain what exactly does "the value of this is incorrect" mean?

    It means it's not ron, which is what we intended, but didn't achieve.

    The .map method invokes the function like this: f(x) and not like obj.f(x). It invokes it as a normal function, not as a method. So, the value of this isn't set correctly.

  • Not sure I understand, is it correct that after Account.prototype.deposit.bind(ron) using deposit.bind(ron) will deposit to Ron's account, no matter what account the function is called on?

    Good question, and yes, you're mostly right.

    But, well, the function isn't called on an account. Consider the following:

    
        const f = Account.prototype.deposit.bind(ron);
        f(10); // deposit 10 in ron's account
        // how would we even try to use f to deposit in someone else's account?
        harry.f(10); // error: harry has no "f" method
    
    
    The f function is a normal function that deposits into ron's account. It's not a method. And so there's no way to adjust the value of this that it has bound. It's locked in.
  • No question for now! / No questions! / No particular questions right now.

    Amazing! Most students struggle with this