Created
October 30, 2014 00:47
-
-
Save JacobHsu/39b85337aab99af68d16 to your computer and use it in GitHub Desktop.
#JS Accessing Private Variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Person(first,last,age) { | |
this.firstname = first; | |
this.lastname = last; | |
this.age = age; | |
var bankBalance = 7500; | |
this.getBalance = function() { | |
// your code should return the bankBalance | |
return bankBalance; | |
}; | |
} | |
var john = new Person('John','Smith',30); | |
console.log(john.bankBalance); | |
// create a new variable myBalance that calls getBalance() | |
var myBalance = john.getBalance(); | |
console.log(myBalance); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment