Skip to content

Commit 339bff9

Browse files
committed
Extra practice with prototype and inheritance
1 parent ca4950d commit 339bff9

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

‎constructors.js‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ function Animal(options) {
99
}
1010

1111
// add 'grow' to Animal's prototype here
12+
Animal.prototype.grow = function(){
13+
return `${this.name} grew larger!`
14+
}
1215

1316
// problem #2
1417
// setup Cat to inherit from Animal
@@ -18,16 +21,19 @@ function Animal(options) {
1821

1922
function Cat(options) {
2023
// invoke Animal here with .call
24+
Animal.call(this,options)
2125
}
2226

27+
Cat.prototype = Object.create(Animal.prototype);
28+
2329
// connect the prototypes here
2430

2531
// if everything is setup properly the code below will print 'Foofie grew larger!'
2632
// uncomment the code below to test your solution
2733

28-
// const foofie = new Cat({
29-
// name: 'foofie',
30-
// });
31-
//
32-
// foofie.grow();
34+
const foofie = new Cat({
35+
name: 'foofie',
36+
});
37+
38+
console.log(foofie.grow());
3339

0 commit comments

Comments
 (0)