25 Private Methods (Quick Question Please)


#1



https://www.codecademy.com/en/courses/objects-ii/4/4?curriculum_id=506324b3a7dffd00020bf661#

Hi, Ive managed to pass the lesson but i just wondering why we have to create the var MyBalanceMethod just to then create the variable "MyBalance".

In my head it just seems that john.askTeller = myBalanceMethod = myBalance, so why do we need to middle man "myBalanceMethod"?

I did try just using console.log(myBalanceMethod) but it just return as function.

If anyone can just quickly explain this so i can fully get my head around it that would be great.

Thanks.


var myBalanceMethod = john.askTeller();
var myBalance = myBalanceMethod();
console.log(myBalance);


#2

Because askTeller returns a method, we need to call it to make it any use. This is what

var myBalance = myBalanceMethod();

does.
you can use

console.log(myBalanceMethod());

too.just remember you need to call it.askTeller returns the returnBalance method. This means that it returns the method itself and NOT the result of calling that method.

@tagcoder00645