Quiz
- Could you explain the map question on quiz14b?
Sure. That question asks why the following fails:
It fails because the
depositfunction is pulled out of the ron object (which in fact gets it from theAccount.prototype) and that function is:But the keyword
thisis not bound toronor, in fact, any bank account.So, the value of
thisis 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
.mapmethod invokes the function like this:f(x)and not likeobj.f(x). It invokes it as a normal function, not as a method. So, the value ofthisisn'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:
Theffunction 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 ofthisthat it has bound. It's locked in. - No question for now! / No questions! / No particular questions right now.
Amazing! Most students struggle with
this