JSFiddle - React, Tailwind, and code Playground

by Maxim Ivanov

JavaScript

// наследование прототипов (абстрактный тип)

function extend(child, parent) {
    var emptyCtor = function() {};
    emptyCtor.prototype = parent.prototype;
    child.prototype.constructor = child;
    child._super = parent.prototype; // fix
    return child;
};

var ParentClass = function() {
	this.a = 1;
};

var ChildClass = function() {
	ChildClass._super.constructor.call(this) // call parent
  this.b = 2; // add new property
};

var ChildClass = extend(ChildClass, ParentClass);

var myObject = new ChildClass();
document.body.innerHTML = myObject.a + "<br>";
document.body.innerHTML += myObject.b + "<br>";