JS prototype inheritance

Run Settings
LanguageJavaScript
Language Version
Run Command
// Base class function Alert (title) { if (!(this instanceof Alert)) { return new Alert(); } this.title = title || 'alert'; } // Base class method show Alert.prototype.show = function () { console.log(this.title); }; // class extends Base class function SuccessAlert(title) { Alert.call(this, title); this.type = 'success'; } // class methods of extending Base class SuccessAlert.prototype = Alert.prototype; SuccessAlert.prototype.on = function () { console.log('getting on'); }; const message = new SuccessAlert('success'); message.show(); message.on();
Editor Settings
Theme
Key bindings
Full width
Lines