-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14.04.24_hw.js
More file actions
59 lines (48 loc) · 2.38 KB
/
14.04.24_hw.js
File metadata and controls
59 lines (48 loc) · 2.38 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
// 6. Домашнє завдання
// Створіть клас MyButton, який приймає 2 параметри у вигляді тексту (text) та класу кнопки (btnClass).
// Опишіть метод show(), який виводить методом document.write() екземпляр кнопки в тіло HTML-сторінки.
// Передбачте гетер і сетер, які дозволяють отримати та змінити властивість value кнопки,
// яка насправді змінює її властивість-text.
// Опишіть у стиляхкілька класів для сторінки, які дозволять створити різні екземпляри кнопок.
// Виведіть кілька кнопок шляхом show(), для однієї з них змініть текст:
// Створіть клас ColorButton, який успадковує клас MyButton, додавши до нього додатковий клас,
// який дозволяє змінювати колір фону та текст кнопки, додаючи до екземпляра ColorButton крім
// основного ще й додатковий клас. Наприклад, екземпляр ColorButton буде викликатись за такими
class MyButton {
constructor(text, btnClass) {
this._text = text;
this._btnClass = btnClass;
}
show() {
document.write(`<button type="button" class="${this._btnClass}">${this._text}</button>`);
}
get value() {
return this._text;
}
set value(newValue) {
this._text = newValue;
}
}
class ColorButton extends MyButton {
constructor(text, btnClass, colorClass) {
super(text, btnClass);
this._colorClass = colorClass;
}
show() {
document.write(`<button type="button" class="${this._btnClass} ${this._colorClass}">${this._text}</button>`);
}
get colorClass() {
return this._colorClass;
}
set colorClass(newColorClass) {
this._colorClass = newColorClass;
}
}
const btn_1 = new ColorButton("Text", "btn", "btn-success");
const btn_2 = new ColorButton("Text", "btn");
const btn_3 = new ColorButton("Text", "btn");
const btn_4 = new ColorButton("Text", "btn", "btn-danger");
btn_1.value = "Save Progress";
btn_2.value = "Click Me";
btn_3.value = "Download";
btn_4.value = "See More";