JSFiddle - React, Tailwind, and code Playground

by Deepak Anand

JavaScript

// Mimic inheritance without using prototypal relationship/constructor functions

(function(){

  var SuperClass = function () {
    var counter = 0;
    return {
      count: function () {
        counter += 1;
        console.log(counter);
      }
    };
  };
  var SubClass =  function () {
      var self = SuperClass(),
          // get a handle on the super-class method that needs to be extended here
          superCount = self.count;

      self.talk = function () {
          console.log(" i can talk also");
      };
      // extend the super-object's count
      self.count = function () {
          superCount.call(self);
          console.log(" i am count extended");
      };
      return self;
  };
  
  var sub1 = SubClass()
  sub1.count()
})();