JSFiddle - React, Tailwind, and code Playground
JavaScript
function inheritPrototype(subType, superType) {
var prototype = Object.create(superType.prototype, {
constructor: {
value: subType,
enumerable: true
}
});
subType.prototype = prototype;
}
function Rune() {
this.subSpells = {};
}
function Modifier() {
Rune.apply(this, arguments);
this.type = "modifier";
}
inheritPrototype(Modifier, Rune);
function RuneFactory(effect, inheritsFrom, initialValue) {
function toReturn() {
inheritsFrom.apply(this, arguments);
this.subSpells[effect] = initialValue;
}
inheritPrototype(toReturn, inheritsFrom);
return toReturn;
}
Duration = RuneFactory("duration", Modifier, 1);
Quicken = RuneFactory("quicken", Modifier, 1);
x = new Duration();
y = new Quicken();
console.log(x.subSpells.duration); // 1
console.log(x.subSpells.quicken); // undefined
console.log(y.subSpells.duration); // undefined
console.log(y.subSpells.quicken); // 1