我有以下如果,否則if,else構造和我只是好奇我如何能夠將構造轉換爲switch語句。從if轉換到switch語句
var emailSubject = email.subject.toLowerCase();
if(emailSubject.indexOf("account request") >= 0){
//do acct req
}else if(emailSubject.indexOf("accounts pending removal for") >= 0){
//do account removal
}else if(emailSubject.indexOf("listserv application") >= 0){
//do listserv app
}else if(emailSubject.indexOf("student organization webmaster transfer request") >= 0){
//do webmaster xfer
}else{
//do default
}
我的想法是,但我不認爲這是正確的:
switch(emailSubject){
case this.indexOf("account request"):
//do acct request
break;
default:
//do default
}
或者
switch(0){
case emailSubject.indexOf("accounts pending removal"):
//process account pending removal
break;
default:
//do default behavior
}
你爲什麼不試試並調試一樣? – Kangkan 2010-08-26 14:02:44