JSFiddle - React, Tailwind, and code Playground

by alirokni

JavaScript

// defining some attribute as a private one!
function State_Enum() {
  var BP_Main = 0; // private
  var BP_Col = 0; //private

  this.init = function(mode1, mode2) { // public
    BP_Main = mode1;
    BP_Col = mode2;
  };

  this.getBP_Main = function() {
    return BP_Main;
  };
  this.getBP_Col = function() {
    return BP_Col;
  };
}

var se = new State_Enum();
se.init(10, 20);
console.log(se.getBP_Main(), se.getBP_Col());

/*   */

function Car() {
  var color = 'red';
  var engine = 'awd';
  this.init = function(col, eng) {
    color = col;
    engine = eng;
  };
  this.getColor = function() {
    return color;
  };
  this.getEngine = function() {
    return engine;
  };
}

var grayCar = new Car();

grayCar.init('gray', 'rwd');
console.log(grayCar.getColor(), grayCar.getEngine());