Created
January 17, 2016 21:03
-
-
Save andrewjmead/18a551b4287aa85e8f37 to your computer and use it in GitHub Desktop.
Basic Prototype Example With Accounts
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
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