-
Notifications
You must be signed in to change notification settings - Fork 0
/
objectcreate.html
55 lines (44 loc) · 1.17 KB
/
objectcreate.html
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Object create method</title>
</head>
<body>
<div id="app"></div>
<script>
// Object Created
const Client = {
getBalance: function() {
return `hello ${this.name} your balance is
${this.balance}`;
},
withDraw: function(amount) {
return this.balance -= amount;
},
deposit: function(amount){
return this.balance += amount;
}
}
// Create new object and give balance
const mary = Object.create(Client);
// ATTACH the properties
mary.name = 'Haben';
mary.balance = 1000;
console.log(mary);
console.log(mary.getBalance());
// withDraw
mary.withDraw(500);
console.log(mary.getBalance());
//Deposit some money
mary.deposit(1200);
console.log(mary.getBalance());
// Another method
const haben = Object.create(Client, {
name: {value: 'Haben'},
balance: {value: 1000}
})
console.log(haben);
</script>
</body>
</html>