第一章1.8节的源代码重写:
![ContractedBlock.gif](/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
var Operation = {
GetResult: function(numA, numB, operate) {
var result = 0.00;
switch(operate) {
case '+':
result = numA + numB;
break;
case '-':
result = numA - numB;
break;
case '*':
result = numA * numB;
break;
case '/':
result = numA / numB;
break;
}
return result;
}
}
程序部分:
![ContractedBlock.gif](/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
Program = {
main: function() {
if(!document.getElementById) return;
try {
var sNumA = document.getElementById('numA').value;
var sOperate = document.getElementById('operate').value;
var sNumB = document.getElementById('numB').value;
var sResult = '';
sResult = (Operation.GetResult(Number(sNumA), Number(sNumB), sOperate)).toString();
document.getElementById('compute').onclick = function() {
return document.getElementById('result').innerHTML = sResult;
}
}
catch(e) {
console.log('你的输入有误:' + e);
}
}
}