Skip to content

Instantly share code, notes, and snippets.

@JacobHsu
Created October 30, 2014 00:47
Show Gist options
  • Save JacobHsu/39b85337aab99af68d16 to your computer and use it in GitHub Desktop.
Save JacobHsu/39b85337aab99af68d16 to your computer and use it in GitHub Desktop.
#JS Accessing Private Variables
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