【发布时间】:2012-12-11 13:24:30
【问题描述】:
我正在使用 Html5-js-jquery 开发 win8(metro 风格)应用程序。 我有这个代码段;
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 部分?
【问题讨论】:
-
为什么这些函数都是大写的?他们似乎不是构造函数。
标签: javascript microsoft-metro