JSFiddle - React, Tailwind, and code Playground
HTML
X: <input id='x'>
<br>
Y: <input id='y'>
<br>
Res: <input id='res'>
<br>
<input id='sum' type='button' value='+'>
<input id='subt' type='button' value='-'>
<input id='mult' type='button' value='*'>
<input id='div' type='button' value='/'>
<input id='clean' type='button' value='C'>
<input id='rand' type='button' value='Rand'>
JavaScript
var OPERATORS = (function ($) {
var self = {};
//private
var IPT_X = '#x';
var IPT_Y = '#y'
//public
self.x = 0;
self.y = 0;
self.showOperators = function() {
//use of a private property (IPT_X) and a public property (self.x)
$(IPT_X).val(self.x);
$(IPT_Y).val(self.y);
};
self.clean = function() {
self.x = 0;
self.y = 0;
// call to a local public method
self.showOperators();
};
self.updateOperators = function(_x, _y) {
// use of a public property when call from
// derived class method is necessary
self.x = _x;
self.y = _y;
}
return self;
})(jQuery);
var RANDOMIZER = (function(self, math) {
var super_updateOperators = self.updateOperators;
// private
function getRandomNumber() {
return math.round(Math.random() * 1000);
};
// public
self.updateOperators = function(_x, _y) {
// call to inherited method of superior class
super_updateOperators(_x, _y);
// call to method of superior class
self.showOperators();
};
self.populateRandomNumbers = function() {
// call to public local method (this.updateOperators())
// and to a local private method (getRandomNumber())
self.updateOperators(getRandomNumber(), getRandomNumber());
};
// init
self.populateRandomNumbers();
return self;
})(OPERATORS, Math)
var OPERATIONS = (function(self, $) {
//private
var IPT_RES = '#res'
var BTN_SUM = '#sum'
var BTN_SUBTRACT = '#subt'
var BTN_MULTIPLY = '#mult'
var BTN_DIVISION = '#div'
var BTN_CLEAN = '#clean'
var BTN_RAND = '#rand'
function calcSum() {
return self.x + self.y
}
function calcSubtraction() {
return self.x - self.y
}
function calcMultiplication() {
return self.x * self.y
}
function...