File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,11 +12,13 @@ function Animal(options) {
1212Animal . prototype . grow = function ( ) {
1313 console . log ( `${ this . name } grew larger` ) ;
1414}
15+ // new instance of Animal
1516const zebra = new Animal ( {
1617 name : 'Will'
1718} ) ;
18- console . log ( zebra ) ;
19- console . log ( zebra . grow ( ) ) ;
19+ console . log ( zebra ) ; // { name: 'Will' }
20+ // this refers to the zebra object
21+ console . log ( zebra . grow ( ) ) ; // 'Will grew larger'
2022// problem #2
2123// setup Cat to inherit from Animal
2224// the Animal constructor needs to be invoked with the 'options' argument
@@ -25,16 +27,18 @@ console.log(zebra.grow());
2527
2628function Cat ( options ) {
2729 // invoke Animal here with .call
30+ Animal . call ( this , options ) ;
2831}
2932
3033// connect the prototypes here
31-
34+ // link Cat proto with its parents proto and everything in it
35+ Cat . prototype = Object . create ( Animal . prototype ) ;
3236// if everything is setup properly the code below will print 'Foofie grew larger!'
3337// uncomment the code below to test your solution
3438
35- // const foofie = new Cat({
36- // name: 'foofie',
37- // });
38- //
39- // foofie.grow();
39+ const foofie = new Cat ( {
40+ name : 'foofie' ,
41+ } ) ;
42+
43+ foofie . grow ( ) ;
4044
You can’t perform that action at this time.
0 commit comments