Skip to content

Instantly share code, notes, and snippets.

@javaeeeee
Created September 24, 2014 04:35
Show Gist options
  • Save javaeeeee/18c9e202330e78ffb076 to your computer and use it in GitHub Desktop.
Save javaeeeee/18c9e202330e78ffb076 to your computer and use it in GitHub Desktop.
BankAccount Module
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