JSFiddle - React, Tailwind, and code Playground
JavaScript
$(function() {
document.write("<pre>");
var Parent = function() {return this;};
Parent.prototype.someObject = {one: 1, two: 2};
var A = function() {Parent.apply(this, arguments);};
A.prototype = Object.create(Parent.prototype);
$.extend(true, A.prototype, {
constructor: A,
someObject: {Aone: 1, Atwo: 2},
});
var B = function() {Parent.apply(this, arguments);};
B.prototype = Object.create(Parent.prototype);
$.extend(true, B.prototype, {
constructor: B,
someObject: {Bone: 1, Btwo: 2},
});
var parent = new Parent();
var a = new A();
var b = new B();
document.write("Magically modifing prototypes<br />");
document.write("A.prototype " + JSON.stringify(A.prototype) + "<br />");
document.write("B.prototype " + JSON.stringify(B.prototype) + "<br />");
document.write("Parent.prototype " + JSON.stringify(Parent.prototype) + "<br />");
});
document.write("<br /><br />");
$(function() {
var Parent = function() {return this;};
Parent.prototype.someObject = {one: 1, two: 2};
var A = function() {Parent.apply(this, arguments);};
A.prototype = Object.create(Parent.prototype);
A.prototype = $.extend(true, {}, A.prototype, {
constructor: A,
someObject: {Aone: 1, Atwo: 2},
});
var B = function() {Parent.apply(this, arguments);};
B.prototype = Object.create(Parent.prototype);
B.prototype = $.extend(true, {}, B.prototype, {
constructor: B,
someObject: {Bone: 1, Btwo: 2},
});
var parent = new Parent();
var a = new A();
var b = new B();
document.write("Propper prototypes<br />");
document.write("A.prototype " + JSON.stringify(A.prototype) + "<br />");
document.write("B.prototype " + JSON.stringify(B.prototype) + "<br />");
document.write("Parent.prototype " + JSON.stringify(Parent.prototype) + "<br />");
document.write("</pre>");
});