JSFiddle - React, Tailwind, and code Playground
by Givi Kesanashvili
JavaScript
(function () {
"use strict";
function inheritPrototype(subType, superType) {
var prototype = Object.create(superType.prototype, {
constructor: {
value: subType,
enumerable: true
}
});
subType.prototype = prototype;
}
function Person(firstName, lastName, age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
if (typeof Person.prototype.fullInfo !== "function") {
Object.defineProperties(Person.prototype, {
fullInfo: {
value: function () {
return this.firstName + " " + this.lastName + "\n" + this.age;
},
enumerable: true,
writable: true,
configurable: true
}
});
}
}
function Employee(firstName, lastName, age, job) {
Person.apply(this, arguments);
this.job = job;
if (!Employee.prototype.hasOwnProperty("fullInfo")) {
Object.defineProperties(Employee.prototype, {
fullInfo: {
value: function () {
var desc = Object.getOwnPropertyDescriptor(Person.prototype, "fullInfo").value.call(this);
return desc + "\n" + this.job;
},
enumerable: true,
writable: true,
configurable: true
}
});
}
}
inheritPrototype(Employee, Person);
var gk = new Employee("G", "K", 24, "Programmer");
alert(gk.fullInfo());
}());