File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33// problem #1
44// convert the Animal constructor function from 'constructors.js' into an ES6 class
5+ class Animal {
6+ constructor ( options ) {
7+ this . name = options . name ;
8+ }
9+ grow ( ) {
10+ console . log ( `${ this . name } grew larger!` ) ;
11+ }
12+ }
513
614
715// problem #2
816// convert the Cat constructor function from 'constructors.js' into an ES6 class
917
18+ class Cat extends Animal {
19+ meow ( ) {
20+ console . log ( 'meow!' ) ;
21+ }
22+ }
1023
1124// if everything is setup properly the code below will print 'Foofie grew larger!'
1225// uncomment the code below to test your solution
1326
14- // const foofie = new Cat({
15- // name: 'foofie',
16- // });
17- //
18- // foofie.grow();
27+ const foofie = new Cat ( {
28+ name : 'foofie' ,
29+ } ) ;
1930
31+ foofie . grow ( ) ;
32+ foofie . meow ( ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,10 @@ function Animal(options) {
88 this . name = options . name ;
99}
1010
11+ Animal . prototype . grow = function ( ) {
12+ console . log ( `${ this . name } grew larger!` ) ;
13+ } ;
14+
1115// add 'grow' to Animal's prototype here
1216
1317// problem #2
@@ -17,17 +21,20 @@ function Animal(options) {
1721// instances of Cat should also have access to the 'grow' method
1822
1923function Cat ( options ) {
24+ Animal . call ( this , options ) ;
2025 // invoke Animal here with .call
2126}
2227
28+ Cat . prototype = Object . create ( Animal . prototype ) ;
29+
2330// connect the prototypes here
2431
2532// if everything is setup properly the code below will print 'Foofie grew larger!'
2633// uncomment the code below to test your solution
2734
28- // const foofie = new Cat({
29- // name: 'foofie',
30- // });
31- //
32- // foofie.grow();
35+ const foofie = new Cat ( {
36+ name : 'foofie' ,
37+ } ) ;
38+
39+ foofie . grow ( ) ;
3340
You can’t perform that action at this time.
0 commit comments