JSFiddle - React, Tailwind, and code Playground
by NerfAnarchist
JavaScript
// swiss inheritance
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
Function.method('swiss', function (parent) {
for (var i = 1; i < arguments.length; i += 1) {
var name = arguments[i];
this.prototype[name] = parent.prototype[name];
}
return this;
});
function Parenizor(value) {
this.setValue(value);
}
Parenizor.method('setValue', function (value) {
this.value = value;
return this;
});
Parenizor.method('getValue', function () {
return this.value;
});
function Parenizor2(value) {
this.setValue(value);
}
Parenizor2.method('toString', function () {
return '(' + this.getValue() + ')';
});
Parenizor.swiss(Parenizor2, 'toString', 'wfegwe');
var ObjectWithCombinedMethods = new Parenizor(123);
ObjectWithCombinedMethods.setValue(2345)
alert( ObjectWithCombinedMethods.toString() );