JSFiddle - React, Tailwind, and code Playground
JavaScript
// Base constructor, like a baseclass in Java
function Base() {
this.baseProperty = "baseValue";
}
// Base implementation of a method
Base.prototype.printSelf = function () {
console.log(this.baseProperty);
};
// Constructor, corresponding to a subclass in Java
function Obj() {
// Call "baseclass" constructor
Base.call(this);
this.property = "someValue";
}
// Inherit prototype from Base
Obj.prototype = Object.create(Base.prototype);
// Overload printSelf
Obj.prototype.printSelf = function () {
// Call base implementation
Base.prototype.printSelf.call(this);
console.log(this.property);
};
var obj = new Obj();
obj.printSelf();