Skip to content

Commit 4432292

Browse files
committed
upload solutions to problem 2 and added comments
1 parent 10805c2 commit 4432292

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

constructors.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ function Animal(options) {
1212
Animal.prototype.grow = function() {
1313
console.log(`${this.name} grew larger`);
1414
}
15+
// new instance of Animal
1516
const 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

2628
function 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

0 commit comments

Comments
 (0)