Repository navigation
Expand file tree
/
Copy pathclass.js
More file actions
92 lines (75 loc) · 2.09 KB
/
Copy pathclass.js
File metadata and controls
92 lines (75 loc) · 2.09 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// class Storage {
// constructor(items) {
// this.items = items;
// }
// getItems(){
// return this.items;
// }
// addItem(newItem){
// return this.items.push(newItem);
// }
// removeItem(itemToRemove) {
// const index = this.items.indexOf(itemToRemove);
// if (index !== -1) {
// this.items.splice(index, 1);
// }
// }
// }
// // Change code above this line
// const storage = new Storage(["Nanitoids", "Prolonger", "Antigravitator"]);
// console.log(storage.getItems()); // ["Nanitoids", "Prolonger", "Antigravitator"]
// storage.addItem("Droid");
// console.log(storage.getItems()); // ["Nanitoids", "Prolonger", "Antigravitator", "Droid"]
// storage.removeItem("Prolonger");
// console.log(storage.getItems()); // ["Nanitoids", "Antigravitator", "Droid"]
// class Car {
// // Change code below this line
// #brand
// constructor({ brand, model, price }) {
// this.#brand = brand;
// this.model = model;
// this.price = price;
// }
// getBrand(){
// return this.#brand;
// }
// changeBrand(newBrand){
// this.#brand = newBrand;
// }
// // Change code above this line
// }
// class User {
// static #takenEmails = [];
// static isEmailTaken(email) {
// return User.#takenEmails.includes(email);
// }
// #email;
// constructor({ email }) {
// this.#email = email;
// User.#takenEmails.push(email);
// }
// }
// const mango = new User({ email: "mango@mail.com" });
// console.log(User.isEmailTaken("poly@mail.com"));
// console.log(User.isEmailTaken("mango@mail.com"));
class User {
constructor(email) {
this.email = email;
}
get email() {
return this.email;
}
set email(newEmail) {
this.email = newEmail;
}
}
class ContentEditor extends User {
constructor({ email, posts }) {
// Виклик конструктора батьківського класу User
super(email);
this.posts = posts;
}
}
const editor = new ContentEditor({ email: "mango@mail.com", posts: [] });
console.log(editor); // { email: 'mango@mail.com', posts: [] }
console.log(editor.email); // 'mango@mail.com'