JSFiddle - React, Tailwind, and code Playground
JavaScript
function Person() {
this.text = "Hello";
}
Person.prototype.say = function () {
alert(this.text);
}
function TalkativePerson() {
Person.apply(this);
this.extendedText = "How are you ?";
}
TalkativePerson.prototype = Object.create(Person.prototype);
TalkativePerson.prototype.constructor = TalkativePerson;
TalkativePerson.prototype.say = function () {
Person.prototype.say.call(this);
alert(this.extendedText);
}
function TalkativePerson2() {
this.text += ". How are you ?";
}
TalkativePerson2.prototype = new Person();
var person = new TalkativePerson();
person.say();
var person2 = new TalkativePerson2();
person2.say();