I have to make it dynamic because I'm calling it from a click and checking some things before deciding which function to call. For example I'm checking screen size and then calling functions based on that as well as another value. The two put together make up the existing function name.
I was thinking of using a switch statement but that would bloat the code and I was really hoping for less code to manage and hopefully a smaller file size. Looks like the method @traq suggested seems to be the better option.
Is it possible to use a variable as a function name?
For example:
When I try to use that, I get an error that string is not a function, but there is a function named as that?
Why wouldn't you just call
my_function()?What you can do is this:
I have to make it dynamic because I'm calling it from a click and checking some things before deciding which function to call. For example I'm checking screen size and then calling functions based on that as well as another value. The two put together make up the existing function name.
works in Chrome. didn't test elsewhere.
Thanks @traq! So far, my testing has been successful in a few browsers!
Couldn't you use a Switch statement to determine which to call?
Then, if you wanted to add another possibility, all you really have to do is add a case.
I was thinking of using a switch statement but that would bloat the code and I was really hoping for less code to manage and hopefully a smaller file size. Looks like the method @traq suggested seems to be the better option.