bradxr
8/5/2018 - 11:26 PM

Use Inheritance So You Don't Repeat Yourself

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

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


// 2
function Animal() { };

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


// 3
Bird.prototype = {
  constructor: Bird
};

Dog.prototype = {
  constructor: Dog
};