-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy path1_S.js
56 lines (46 loc) · 913 Bytes
/
1_S.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
// Single Responsibility Principle
class News {
constructor(title, text) {
this.title = title
this.text = text
this.modified = false
}
update(text) {
this.text = text
this.modified = true
}
}
class NewsPrinter {
constructor(news) {
this.news = news
}
html() {
return `
<div class="news">
<h1>${this.news.title}</h1>
<p>${this.news.text}</p>
</div>
`
}
json() {
return JSON.stringify({
title: this.news.title,
text: this.news.text,
modified: this.news.modified
}, null, 2)
}
xml() {
return `
<news>
<title>${this.news.title}</title>
<text>${this.news.text}</text>
</news>
`
}
}
const printer = new NewsPrinter(
new News('Путин', 'Новая конституция')
)
console.log(printer.html())
console.log(printer.xml())
console.log(printer.json())