Created
January 29, 2012 23:27
-
-
Save eyston/1701339 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var account = (function(startingBalance) { | |
var balance = startingBalance; | |
function getBalance() { | |
return balance; | |
} | |
function deposit(amount) { | |
balance += amount; | |
} | |
function withdraw(amount) { | |
balance -= amount; | |
} | |
return { | |
getBalance: getBalance, | |
deposit: deposit, | |
withdraw: withdraw | |
}; | |
}); | |
var accountOne = account(0); | |
var accountTwo = account(100); | |
console.log(accountOne.getBalance()); // 0 | |
console.log(accountTwo.getBalance()); // 100 | |
accountOne.deposit(50); | |
console.log(accountOne.getBalance()); // 50 | |
console.log(accountTwo.getBalance()); // 100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment