javascript可用数组取代case格式化字符
这种方式代码更简洁:
可对比swich,case的方法:
function getTypes(classid) {
var types = [];
types["1"] = "R";
types["2"] = "S";
types["3"] = "D";
types["4"] = "C";
types["5"] = "F";
types["6"] = "H";
return types[classid];
}
var types = [];
types["1"] = "R";
types["2"] = "S";
types["3"] = "D";
types["4"] = "C";
types["5"] = "F";
types["6"] = "H";
return types[classid];
}
function getTypes(classid) {
var str="";
switch(classid)
{
case "1":
str = "R";
break;
case "2":
str = "S";
break;
case "3":
str = "D";
break;
case "4":
str = "C";
break;
case "5":
str = "F";
break;
case "6":
str = "H";
break;
default:
str = "";
break;
}
return str;
}
var str="";
switch(classid)
{
case "1":
str = "R";
break;
case "2":
str = "S";
break;
case "3":
str = "D";
break;
case "4":
str = "C";
break;
case "5":
str = "F";
break;
case "6":
str = "H";
break;
default:
str = "";
break;
}
return str;
}