Skip to content

Instantly share code, notes, and snippets.

@andrewjmead
Created January 17, 2016 21:03
Show Gist options
  • Save andrewjmead/18a551b4287aa85e8f37 to your computer and use it in GitHub Desktop.
Save andrewjmead/18a551b4287aa85e8f37 to your computer and use it in GitHub Desktop.
Basic Prototype Example With Accounts
function Account(balance) {
this.balance = balance || 0;
}
Account.prototype.deposit = function(amount) {
this.balance += amount;
};
Account.prototype.withdraw = function(amount) {
this.balance -= amount;
};
Account.prototype.getbalance = function() {
console.log('You have ' + this.balance + ' in your account');
}
console.log('First Account');
var account = new Account(0);
account.getbalance();
account.deposit(1200);
account.getbalance();
account.withdraw(200);
account.getbalance();
console.log('Second Account');
var secondAccount = new Account(1000);
secondAccount.deposit(1200);
secondAccount.getbalance();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment