After reading up online I wrote this simple code that does addition and multiplication via chaining. But reading the code, it looks like to me, that the method "Result" makes the code less readable and kind of seems redundant. Can someone help me get rid of the Result function?
var Calculator = function () {
var result = 0;
this.Add = function (x) {
result = result + x;
return this;
};
this.Multiply = function (x) {
result = result * x;
return this;
};
this.Result = function () {
return result;
}
};
var total = new Calculator().Add(2).Add(3).Multiply(5);
alert(total.Result());
What I am trying to achieve is
var total = new Calculator().Add(2).Add(3).Multiply(5);
alert(total);