下面給出一個完成的函數,仔細的體會一下。
function getConditions(strCity : String) : String
{
var now : Date = new Date();
switch (strCity.toUpperCase())
{
case "LONDON":
if (now.getMonth() <= 7 || now.getMonth() >= 9)
{
return "overcast";
}
else
{
return "partly overcast and humid";
}
break;
case "SEATTLE":
if (now.getMonth() == 7 && now.getDay() == 4)
{
return "torrential rain";
}
else
{
return "rain";
}
break;
case "LA":
return "smoggy";
break;
case "PHOENIX":
return "damn hot";
break;
default:
return "partly cloudy with a chance of showers";
}
}
使用Jscript.net,你也可以定義其他.net架構的類型,通過引用命名空間和派生類可以向JScript.Net引入新的數據類型。這樣在兩者的數據類型中就有可能產生重疊。參見下表:
Boolean .Net Framework Boolean / JScript boolean
Number .Net Framework Double / JScript number
String .Net Framework String / JScript string
Int .Net Framework Int32
Long .Net Framework Int64
Float .Net Framework Single
Double .Net Framework Double
Object .Net Framework Object / JScript Object
Date JScript Date object
Array JScript Array
Function JScript Function object