OLOO/ aka (Prototype Inheritance)
https://github.com/getify/You-Dont-Know-JS/blob/master/this%20&%20object%20prototypes/ch6.md#delegation-theory
--
http://addyosmani.com/resources/essentialjsdesignpatterns/book/#prototypepatternjavascript
by Julien Etienne
JavaScript
var BankAccount = {
_balance: 0,
checkBalance: function () {
console.log('Your balance is $' + this._balance);
},
deposit: function (deposit) {
this._balance += deposit;
console.log('You have deposited $' + deposit + ' your new balance is $' + this._balance);
},
withdrawal: function (withdrawal) {
this._balance -= withdrawal;
console.log('You withdrew $' + withdrawal + ' your new balance is $' + this._balance);
}
};
// Instantiation
var SavingsAccount = Object.create(BankAccount);
var CurrentAccount = Object.create(BankAccount);
// Use Savings Account
SavingsAccount.deposit(3000);
SavingsAccount.withdrawal(500);
SavingsAccount.checkBalance();
// Use Current Account
CurrentAccount.deposit(1234);
CurrentAccount.withdrawal(4000);
CurrentAccount.checkBalance();
// Check proto
console.log(CurrentAccount.withdrawal.prototype); // BankAccount.withdrawal {}