JSFiddle - React, Tailwind, and code Playground
JavaScript
function SuperColors() {
this.colors = ["red", "orange", "yellow"];
}
SuperColors.prototype.sayColors = function () {
alert("SuperColors " + this.colors);
};
function SubColors() {
//inherit properties
SuperColors.call(this);
}
// inherit methods
SubColors.prototype = new SuperColors();
SubColors.prototype.sayRainbow = function () {
alert(this.colors + "a whole rainbow!");
};
// create an instance of SubColors
var instance1 = new SubColors();
// push colors to colors property on instance
instance1.colors.push("green", "blue", "purple");
alert(instance1.colors); // "red, orange, yellow, green, blue, purple"
instance1.sayColors(); // "SuperColors red,orange,yellow,green,blue,purple";
// delete instance of colors
delete(instance1.colors);
console.log(instance1);
// this should manipulate SuperColor's constructor of colors
instance1.colors.push("green", "blue", "purple");
// instantiate a new SubColor object that should inherit SuperColor's entire rainbow
var instance2 = new SubColors();
delete instance2.colors;
alert(instance1.colors);
alert(instance2.colors); // WHY ISN'T THIS THE ENTIRE RAINBOW? It should have been instantiated with SuperColor's modified colors.
console.log(instance2); // Shows that SuperColors.colors has the rainbow, but the instance has only 3 colors?