Define the constructor property on the Dog prototype. 1

Define the constructor property on the Dog prototype.

function Dog(name) {
  this.name = name;
}
Dog.prototype = {
  constructor: Dog,
  numLegs: 4,
  eat: function() {
    console.log("nom nom nom");
  },
  describe: function() {
    console.log("My name is " + this.name);
  }
};

Here is what the above code is Doing:
1. We create a new object called Dog.
2. We set Dog’s prototype to be a new, empty object with no properties or methods.
3. We add properties and methods to Dog’s prototype.
4. We create a new Dog instance object.
5. We assign the name property to our Dog instance.
6. We then print the name property.

Similar Posts