How To Refactor If-else Code Segment?
Posted
by
LostInLib
on Stack Overflow
See other posts from Stack Overflow
or by LostInLib
Published on 2012-12-11T13:24:30Z
Indexed on
2012/12/17
11:03 UTC
Read the original article
Hit count: 195
JavaScript
|microsoft-metro
I'm developing win8(metro style) application with Html5-js-jquery. I have this code segment;
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);
}
},....
.And ~20 functions should check if user login or not. I should call functions like similar to "Library.GetBoutiqueDetail();"
So my question is simple, how can I refactor that code to remove these if-else sections ?
© Stack Overflow or respective owner