Calling a Function Based on a String Which Contains the Function Name
- by Phonethics
var foo1,foo2;
switch (fn)
{
case "fade" : foo1 = "fadeOut"; foo2 = "fadeIn"; break;
case "slide" : foo1 = "slideUp"; foo2 = "slideDown"; break;
}
eval("$('.cls1')." + foo1 + "();");
currentSlideIndex = currentSlideIndex + n;
eval("$('.cls1')." + foo2 + "();");
Any better way to achieve this without using eval ? Im not a very big fan of using eval unless absolutely necessary.