JSFiddle - React, Tailwind, and code Playground
by alirokni
JavaScript
var oMath = {
result: 0,
'+': function (x, y) {
this.result = x + y;
return this;
},
'-': function (x, y) {
this.result = x - y;
return this;
},
'*': function (x, y) {
this.result = x * y;
return this;
},
'/': function (x, y) {
this.result = x / y;
return this;
},
showResult: function () {
console.log(this.result);
return this;
}
};
oMath['/'](130.5, 2).showResult();
var myMath = {
result: 0,
doMath: function (x, sign, y) {
this.result = eval(x + sign + y);
return this;
},
showResult: function () {
console.log(this.result);
return this;
}
};
myMath.doMath(25, '-', 10).showResult();