Created
September 24, 2014 04:35
-
-
Save javaeeeee/18c9e202330e78ffb076 to your computer and use it in GitHub Desktop.
BankAccount Module
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
var BankAccountModule = (function () { | |
var balance = 0.; | |
function _isEnoughMoney(amount) { | |
return balance > amount; | |
} | |
function deposit(amount) { | |
balance += amount; | |
} | |
function withdraw(amount) { | |
if (_isEnoughMoney(amount)) { | |
balance -= amount; | |
} | |
} | |
function getBalance() { | |
return balance; | |
} | |
return { | |
deposit: deposit, | |
withdraw: withdraw, | |
getBalance: getBalance | |
}; | |
})(); | |
//Adds some money | |
BankAccountModule.deposit(20.); | |
//Prints balance | |
console.log("balance = " + BankAccountModule.getBalance()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment