Object Oriented Programming: Use Inheritance So You Don't Repeat Yourself

Object Oriented Programming: Use Inheritance So You Don't Repeat Yourself
0

#1

Good Morning Campers…

So I need a small ball peen Hammer to get this little item into the brain please…

In the coding example… they give us :

Animal.prototype = {
  constructor: Animal, 
  describe: function() {
    console.log("My name is " + this.name);
  }
};

Bird.prototype = {
  constructor: Bird
};

Dog.prototype = {
  constructor: Dog
};

The end result being that you create the supertype of " Animal " which will of course eliminate the repeated code in both the subtype objects… I get that…

I also get that in the usub versions, the prototype is inherited by the " new" descriptor for the constructor… but what I am missing is that although logically there is a new duck object, that is the new"Bird" object, if the supertype were Animal - how does the code connect Animal to Bird ?

Thanks in advance… the spirit is willing but head is hard LOL


#2

:confused: It doesn’t connect them - I’ve seen this crop up a few times and it is pretty confusing (I’m sure I filed an bug/issue for it ages ago, but anyway). Basically, the next challenge actually shows how the two get connected, it’s just that the explanation doesn’t really make that clear


#3

Thanks Dan,

I appreciate knowing it was just not me being brain dead LOL…
Moving on to the next challenge then… Thank you also for taking the time to reply.
I was in another on line class for front-end developement… and simply dropped it for a number of reasons not the least of which was the lack of response from people who were supposed to be there to assist.
The administrators of the class took at one point 3 months to respond to an email I sent them asking for information. FCC has been a blessing

Thanks again !