JSFiddle - React, Tailwind, and code Playground

by badsyntax

JavaScript

function MyClass() {  
  // public API  
  return {
    publicMethod: this.publicMethod.bind(this)
  };
}

MyClass.prototype.publicMethod = function() {
  this.privateMethod();
};

MyClass.prototype.privateMethod = function() {
  alert('called private method');
};

function SubClass() {
    return MyClass.call(this);   
}

SubClass.prototype = Object.create(MyClass.prototype);

// Here we override the private method
SubClass.prototype.privateMethod = function() {
    MyClass.prototype.privateMethod.call(this);
    alert('called subclass private method');
};

var b = new SubClass();
b.publicMethod();