Prototype-based Inheritance in JavaScript with Constructors using Object.create()

var Animal = { speak() { console.log(this.name + ' makes'); } }; // Defines an object Animal with a speak method class Dog { constructor(name) { this.name = name; } } // Defines a Dog class with a constructor Object.setPrototypeOf(Dog.prototype, Animal); // Sets the prototype of Dog's prototype to Animal's prototype // If you do not do this you will get a TypeError when you invoke speak var d = new Dog('people'); // Creates a new instance of Dog with the name 'people' d.speak(); // Outputs: people makes

Output: