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

THE TASK The eat method is repeated in both Cat and Bear. Edit the code in the spirit of DRY by moving the eat method to the Animal supertype.

How does the cat and bear objects inherit the animal properties here? I dont understand.

function Cat(name) {
  this.name = name;

Cat.prototype = {
  constructor: Cat,

function Bear(name) {
  this.name = name;

Bear.prototype = {
  constructor: Bear,

function Animal() { }

Animal.prototype = {
  constructor: Animal,
  eat: function() {
    console.log("nom nom nom");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:107.0) Gecko/20100101 Firefox/107.0

Challenge: Object Oriented Programming - Use Inheritance So You Don’t Repeat Yourself

Link to the challenge:

Yeah, I don’t see it either. I don’t think it’s worded well. I’m assuming that they will inherit it when the code is changed in a future lesson.

Yea very next challenge lmfao! Doh

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.