JSFiddle - React, Tailwind, and code Playground

by Zevan

JavaScript

Function.prototype.copyProps = function(subclass, superclass){
    for(var key in superclass){
      subclass[key] = superclass[key];   
    }
    for (key in superclass.prototype){
      subclass.prototype[key] = superclass.prototype[key];   
    }
}
Function.prototype.inherits = function(SuperClass, subclass, args){
  
  this.copyProps(subclass, SuperClass.apply(null,args));
  this.copyProps(this, SuperClass);
}



function Ball(a, b, c){
  alert([a, b, c]);
  //alert(this);
  // static
  Ball.x = 1;
  // public
  this.x = 100;
  this.y = 100;
  // private 
  var data = "hello";
  return this;
}

var a = new Ball();
a.x = 200;
a.y = 200;

var b = new Ball();
b.x = 50;
b.y = 50;

//alert([a.x, b.x, Ball.x]);

function RedBall(){
   RedBall.inherits(Ball, this, arguments);
   return this;
}
var red = new RedBall(1,2,3);
alert([RedBall.x, red.x]);