forked from wesbos/beginner-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses-FINISHED.html
61 lines (48 loc) · 1.18 KB
/
classes-FINISHED.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
56
57
58
59
60
61
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Classes</title>
<link rel="stylesheet" href="../base.css">
</head>
<body>
<script>
class Pizza {
// constructor
constructor(toppings = [], customer) {
// computer instance property
this.toppings = toppings;
this.customer = customer;
}
// static property
static toppings = ['pepperoni', 'cheese'];
// static method
static randomPizza() {
return new Pizza()
}
// prototype method (almost always this)
eat() {
console.log('CHOMP');
console.log(this.toppings);
console.log(this.slices);
}
// instance property
slices = 10;
// instance method
hi = () => {
console.log('Hiiii');
console.log(this);
}
// Getter Property
get length() {
return this.slices;
}
// Private Fields can only be modified inside a class
#bankBalance = 10000;
}
const myPizza = new Pizza(['onions'], 'Wes Bos');
console.log(myPizza);
</script>
</body>
</html>