我正在用Html5-js-jquery开发win8(metro style)应用程序。 我有这段代码;如何重构If-else代码段?
GetBoutiqueDetail: function (boutiqueId, options) {
if (IsUserLogin()) {
//different job A
} else {
ShowLoginPanel(undefined);
}
},
GetProductDetail: function (boutiqueId, productId, options) {
if (IsUserLogin()) {
//different job B
} else {
ShowLoginPanel(undefined);
}
},
AddBasket: function (productId, productVariantId, quantity, options) {
if (IsUserLogin()) {
//different job C
} else {
ShowLoginPanel(undefined);
}
},....
。并且〜20个函数应该检查用户是否登录。 我应该叫像类似的功能为“Library.GetBoutiqueDetail();”
所以我的问题很简单,我怎么能重构代码,以消除这些的if-else部分?
瓦时y是那些大写的函数?他们似乎不是构造函数。 –