Created
July 1, 2009 19:07
-
-
Save skoon/138984 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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