Skip to content

Instantly share code, notes, and snippets.

@skoon
Created July 1, 2009 19:07
Show Gist options
  • Save skoon/138984 to your computer and use it in GitHub Desktop.
Save skoon/138984 to your computer and use it in GitHub Desktop.
// Before and after refactoring
//
// Before
//
function showMessage(result)
{
if (result == Success ) {
$('#Success').show();
ToggleApplyRemoveButtons();
}
else if (result == Invalid ) {
$('#Invalid').show();
}
else if (result == Expired) {
$('#Expired').show();
}
else if (result == Used) {
$('#Used').show();
}
else if (result == NotEligible) {
$('#NotEligible').show();
}
else if (result = Error) {
$('#Error').show();
}
};
//
// After
//
var statusCodes = {};
$(document).ready(function() {
statusCodes[Invalid] = function() { $('#Invalid').show(); },
statusCodes[Expired] = function() { $('#Expired').show(); },
statusCodes[Used] = function() { $('#Used').show(); },
statusCodes[NotEligible] = function() { $('#NotEligible').show(); },
statusCodes[Error] = function() { $('#Error').show(); },
statusCodes[Success] = function() { $('#Success').show();ToggleApplyRemoveButtons(); }
});
function showMessage(result) {
statusCodes[result]();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment