JSFiddle - React, Tailwind, and code Playground

by secretgspot

JavaScript

//tags: _init _private constructor demo example inheritance javascript js oop private protected prototype public shared static
function print(text) {
    document.write(text);
   document.write('<br />');
}

var  _Type1 = {};
_Type1.s = 1;

function Type1() {
   this._Type1 =  {};
}

Type1.prototype = {};
Type1.prototype._init = function (a, b)  {
   var _private = this._Type1;
   var shared = _Type1;
   _private.x  = 2;
   shared.s += 3;
   print('type Type1: _init(' + a + ', ' + b + ')  called');
   print('type Type1: _private.x: ' + _private.x);
    print('type Type1: shared.s: ' + shared.s);
};
Type1.prototype._fa =  function (a, b) {
   var _private = this._Type1;
   _private.x += 4;
    print('type Type1: _fa(' + a + ', ' + b + ') called');
   print('type Type1:  _private.x: ' + _private.x);
};
Type1.prototype.fb = function (a, b)  {
   print('type Type1: fb(' + a + ', ' + b + ') called');
   this._fa(a,  b);
};
Type1.prototype.fc = function (a, b) {
   var _private =  this._Type1;
   _private.x += 5;
   print('type Type1: fc(' + a + ', ' + b  + ') called');
   print('type Type1: _private.x: ' +  _private.x);
};
Type1.prototype.fd = function (a, b) {
   print('type  Type1: fd(' + a + ', ' + b + ') called');
   this.fc(a, b);
};

var  _Type2 = {};
_Type2.s = 6;

function Type2() {
    Type1.call(this);
   this._Type2 = {};
}

Type2.prototype = new  Type1();
Type2.prototype._init = function (a, b) {
   var _private =  this._Type2;
   var shared = _Type2;
   print('type Type2: _init(' + a +  ', ' + b + ') started');
   Type1.prototype._init.call(this, b, a);
    _private.x = 7;
   shared.s += 8;
   print('type Type2: _private.x: ' +  _private.x);
   print('type Type2: shared.s: ' + shared.s);
   print('type  Type2: _init(' + a + ', ' + b + ') finished');
};
Type2.prototype._fa =  function (a, b) {
   var _private = this._Type2;
   _private.x += 9;
    print('type Type2: _fa(' + a + ', ' + b + ') called');
   print('type Type2:  _private.x: ' +...