24 Accessing Private Variables - why use function and not a property variable?


I've got the balance to display by assigning the private variable to a property variable, and then calling that property variable. So, I was wondering, why do we bother with the function?

ie, instead of:

this.getBalance = function() {
      // your code should return the bankBalance
      return bankBalance;

why not use this:

this.getBal = bankBalance;

and then console logging john.getBal

Can someone please explain the advantage / need to use the the function instead of this shorter/simpler way?

edit: full code if needed: https://gist.github.com/25815ac296b45fc7cb28d1e883f0ab62


Never mind.
Functions are used because in exercise 26 we need to use an if statement, so this just prepares us.
This can be closed.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.