-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsOOP.js
38 lines (33 loc) · 847 Bytes
/
jsOOP.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
class Book {
constructor(title, author, year) {
this.title = title
this.author = author
this.year = year
this.price = 'PRICE NOT SET'
}
get info() {
return `${this.title} by ${this.author} published ${this.year}`
}
get price() {
return this._price
}
set price(newPrice) {
this._price = newPrice
}
}
const book1 = new Book('Spinning Silver', 'Naomi Novik', 2019)
console.log(book1.info)
class GraphicNovel extends Book {
constructor(title, author, illustrator, year) {
super(title, author, year)
this.illustrator = illustrator
}
get info() {
return `${this.title} written by ${this.author} illustrated by ${this.illustrator} published ${this.year}`
}
}
const myComic = new GraphicNovel('Persepolis', 'name1', 'name2', 2010)
console.log(myComic)
console.log(myComic.info)
myComic.price = 20
console.log(myComic)