Skip to content

Instantly share code, notes, and snippets.

@javaeeeee
Created September 24, 2014 04:28
Show Gist options
  • Save javaeeeee/9a3c815c6712b3ecb025 to your computer and use it in GitHub Desktop.
Save javaeeeee/9a3c815c6712b3ecb025 to your computer and use it in GitHub Desktop.
BankAccount object
var myBankAccount = {
balance: 0,
ownerName: "",
isEnoughMoney: function (amount) {
return balance > amount;
},
deposit: function (amount) {
this.balance += amount;
},
withdraw: function (amount) {
if (this.isEnoughMoney(amount)) {
this.balance -= amount;
}
},
getBalance: function () {
return this.balance;
}
};
//The balance is corrupted
myBankAccount.balance = 20;
//Here we call a method
console.log("balance = " + myBankAccount.getBalance());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment