-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.js
More file actions
67 lines (61 loc) · 1.64 KB
/
classes.js
File metadata and controls
67 lines (61 loc) · 1.64 KB
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
62
63
64
65
66
//factory function
// function pizzaFactory(pizzaSize) {
// const crust = "original"
// const size = pizzaSize
// return {
// bake: () => console.log(`baking a ${size} ${crust} crust pizza`)
// }
// }
// const myPizza = pizzaFactory("small")
// myPizza.bake()
//javascript class
class pizza {
crust = "original"
#sauce = "traditional"
#size
constructor(pizzaSize) {
// this.type = pizzaType;
this.#size = pizzaSize;
// this.toppings = [];
}
getCrust() {
return this.crust;
}
setCrust(pizzaCrust) {
this.crust = pizzaCrust
}
// getToppings() {
// return this.toppings
// }
// setToppings(toppings) {
// this.toppings.push(toppings);
// }
// bake() {
// console.log(`baking a ${this.size},${this.crust},${this.type} crust pizza`);
// }
hereYouGo() {
console.log(`heres your ${this.crust} ${this.#sauce} sauce ${this.#size} pizza`)
}
}
const myPizza = new pizza("large")
myPizza.hereYouGo()
console.log(myPizza.crust);
// const myPizza = new pizza("pepperoni", "large")
// myPizza.type = "chocolate"
// myPizza.setCrust("thin");
// myPizza.bake()
// myPizza.setToppings("sausage");
// myPizza.setToppings("olives");
// console.log(myPizza.getToppings());
// super class/ child class
// class specialPizza extends pizza {
// constructor(pizzaSize) {
// super(pizzaSize);
// this.type = "The Works";
// }
// slice() {
// console.log(`Our ${this.type}, ${this.size} pizza has 8 slices`);
// }
// }
// const mySpecialty = new specialPizza("medium")
// mySpecialty.slice()