Methods can also be private within a class and inaccessible outside of the class. Changing this.returnBalance
from the last exercise to varreturnBalance
makes this method private. If you run the program trying to access the method you get anundefined
error this time.
The way to access a private method is similar to accessing a private variable. You must create a public method for the class that returns the private method.
Create a method called askTeller
within the Person
class that returns thereturnBalance
method. This means that it returns the method itself andNOT the result of calling that method. So you should NOT have parentheses after returnBalance
.