我正在用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是那些大寫的函數?他們似乎不是構造函數。 –