File tree 3 files changed +36
-5
lines changed
3 files changed +36
-5
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ class Book {
11
11
12
12
getAge ( ) {
13
13
const years = new Date ( ) . getFullYear ( ) - this . year ;
14
- return `${ this . title } is ${ years } old` ;
14
+ return `${ this . title } is ${ years } years old` ;
15
15
}
16
16
17
17
revise ( newYear ) {
@@ -24,8 +24,8 @@ class Book {
24
24
25
25
const book1 = new Book ( 'Book One' , 'John Doe' , '2013' ) ;
26
26
console . log ( book1 ) ;
27
- book1 . revise ( '2018' ) ;
28
- console . log ( book1 ) ;
29
-
27
+ // book1.revise('2018');
28
+ // console.log(book1);
29
+ console . log ( book1 . getAge ( ) ) ;
30
30
31
31
Original file line number Diff line number Diff line change 8
8
</ head >
9
9
< body >
10
10
< h2 > JavaScript OOP</ h2 >
11
- < script src ="./SubClass .js "> </ script >
11
+ < script src ="./staticInClass .js "> </ script >
12
12
</ body >
13
13
</ html >
Original file line number Diff line number Diff line change
1
+
2
+ class Book {
3
+
4
+ static newBooks = true ;
5
+ static oldBooks = true ;
6
+
7
+ constructor ( title , author , year ) {
8
+ this . title = title ;
9
+ this . author = author ;
10
+ this . year = year ;
11
+ }
12
+
13
+ getSummary ( ) {
14
+ return `${ this . title } was written by ${ this . author } in year ${ this . year } ` ;
15
+ }
16
+
17
+ getAge ( ) {
18
+ const years = new Date ( ) . getFullYear ( ) - this . year ;
19
+ return `${ this . title } is ${ years } old` ;
20
+ }
21
+
22
+ }
23
+
24
+ const book1 = new Book ( 'Book One' , 'John Doe' , '2013' ) ;
25
+
26
+ // instance of Book do not contain static methods
27
+ console . log ( book1 ) ;
28
+
29
+ // static methods can only be accessed by the class
30
+ console . log ( Book . newBooks ) ;
31
+ console . log ( Book . oldBooks ) ;
You can’t perform that action at this time.
0 commit comments