-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproto.js
More file actions
30 lines (24 loc) · 713 Bytes
/
proto.js
File metadata and controls
30 lines (24 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
Property Lookup
If child does not have ask parent
Everything in JS is an Object
*/
function Account(name, initialBalance) {
this.name = name;
this.balance = initialBalance;
this.bank = "Bank Of America";
//This takes precedence over proto, if not present then it will look property and methods in proto
}
Account.prototype.bank = "CHASE";
Account.prototype.deposit = function (amount) {
this.balance = this.balance + amount;
console.log(`Hello ${this.name}, your balance is ${this.balance}`);
};
const john = new Account("john", 200);
const bob = new Account("bob", 400);
// john.deposit(300);
// bob.deposit(1000);
console.log(john);
console.log(bob.bank);
console.log({});
console.log([]);