Inherit Behaviors from a Supertype

Tell us what’s happening:
I do not understand this function:

function Animal() { }

Why is it empty?

Your code so far


function Animal() { }

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

// Add your code below this line

let duck; // Change this line
let beagle; // Change this line

duck.eat(); // Should print "nom nom nom"
beagle.eat(); // Should print "nom nom nom" 

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/inherit-behaviors-from-a-supertype

It is just a constructor function which is used to help define the prototype for Animal. In this case it does not need to do anything else, so it is empty. However, it still needs to be a function to work.

1 Like