-
Notifications
You must be signed in to change notification settings - Fork 0
/
Decorator.js
74 lines (62 loc) · 1.12 KB
/
Decorator.js
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
67
68
69
70
71
72
73
74
class Car
{
constructor()
{
this.price = 1000000;
this.model = 'Car';
}
getPrice()
{
return this.price;
}
getDescription()
{
return this.model;
}
};
class Testla extends Car
{
constructor()
{
super();
this.price = 1000000;
this.model = "Tesla";
}
};
class Autopilot
{
constructor(car)
{
this.car = car;
}
getPrice()
{
return this.car.getPrice() + 50000;
}
getDescription()
{
return this.car.getDescription() +" with autoPilot";
}
}
class Parktronic
{
constructor(car)
{
this.car = car;
}
getPrice()
{
return this.car.getPrice + 3000;
}
getDescription()
{
return this.car.getDescription()+' with parktronic';
}
}
let testla = new Testla();
testla = new Autopilot(testla);
testla = new Parktronic(testla);
console.log(testla.getPrice(), testla.getDescription());
let testla1 = new Testla();
testla1 = new Autopilot(testla1);
console.log(testla1.getPrice(), testla1.getDescription());