我在javascript中有一个开关,我需要把它与众不同。 如何以更好的方式编写此文件以避免切换?替换JavaScript的swich语句
var types = {
Int: 2,
Short: 3,
Long: 4,
Double: 5,
Decimal: 6,
String: 1,
Guid: 10,
Variant: 11,
};
switch (data.columnTypeId) {
case types.String:
case types.Guid:
case types.Variant:
self.GetStrings(data);
break;
case types.Int:
case types.Decimal:
case types.Short:
case types.Long:
case types.Double:
self.GetNumbers(data);
break;
default:
}
有什么不对的代码?我看起来很棒。 –
一大堆'如果'?也许如果你解释*为什么*你需要替换完美的代码... –
我不想在开关中重复不同的情况 – cmonti