forked from HackYourFuture/JavaScript3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6_classes.js
More file actions
42 lines (32 loc) · 833 Bytes
/
Copy path6_classes.js
File metadata and controls
42 lines (32 loc) · 833 Bytes
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
class Book {
constructor(title, author, year) {
this.title = title;
this.author = author;
this.year = year;
}
getSummary() {
return `${this.title} was written by ${this.author} in ${this.year}.`;
}
getAge() {
const years = new Date().getFullYear() - this.year;
return `${this.title} is ${years} years old.`;
}
revise(newYear) {
this.year = newYear;
this.revised = true;
}
static topBookStore() {
return 'Barnes & Noble';
}
}
// Instantiate an Object
const book1 = new Book('Book One', 'John Doe', 2013);
const book2 = new Book('Book Two', 'Jane Doe', 2016);
console.log(book1);
console.log(book1.getSummary());
console.log(book2.getSummary());
console.log(book2);
book2.revise(2018);
console.log(book2);
console.log(book2.getAge());
console.log(Book.topBookStore());