JSFiddle - React, Tailwind, and code Playground
by demee
JavaScript
function Button(text){
this.text = text;
}
Button.prototype.click = function(){
alert("Clicked");
}
function ToggleButton(text, toggle){
Button.call(this, text);
this.toggle = toggle;
}
ToggleButton.prototype = Object.create(Button, {
toggle : { value: "off", enumerable: true, configurable: true, writable: true },
click : {
value: function(){ // override
Button.prototype.click.apply(this, arguments); // call super
if(this.toggle === "on"){ this.toggle = "off"; } else { this.toggle = "on"; }
alert("Toggle " + this.toggle);
}, enumerable: true, configurable: true, writable: true }
})
var toggleButton = new ToggleButton();
toggleButton.click();