JavaScript 能做的事
為什麼需要這些功能?一個好的理由就是創建數組(array)
創建一個
下面這個特殊的JavaScript 代碼
function state(stateName
//fill the instance with the values passed in
this
this
//then return the instance of state
return this;
}
上面定義的state() 函數創建了包括州名與稅率的一個州(state)的實例
function taxTable(){
//the instance of taxTable is filled with
//an array of state objects
this[
this[
this[
this[
this[
//return the newly created taxTable to
//the calling function
return this;
}
現在
functioncalculateTax(stateValue){
var index=
var result=
var temp=
首先
//while there
//in the taxGuide array
while (taxGuide[index])
{
//if the state passed in is in the
//taxGuide array
if (stateValue
// put the correct tax rate in
result = taxGuide[index]
}
index++;
}
while 循環會持續將用戶的輸入
{
calcTotal();
var temp
// calculate total with tax
var temp
// chop off extra decimal places
vartotalWithTax = (Math
// change value in form
document
totalWithTax;
}
上面的代碼計算包括稅金在內的全部費用
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19178.html