July 2016
Intermediate to advanced
274 pages
6h 11m
English
Let's consider re-factoring the two functions that we looked at previously and putting them together in a more specialized package (class or module) called, CalculationHandler, as shown below:
function CalculationHandler(){
CalculationHandler.result = null;
}
CalculationHandler.doAddition = function(num1, num2){
return num1 + num2;
};
CalculationHandler.doSubtraction = function(num1, num2){
if(num1 > num2){
CalculationHandler.result = num1 - num2;
}else{
CalculationHandler.result = num2 - num1;
}
return CalculationHandler.result;
};
console.log(CalculationHandler.doAddition(3,2)); // displays 5
console.log(CalculationHandler.doSubtraction(3,2)); // displays 1As you can see in this "module" (and I use ...
Read now
Unlock full access