471,893 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,893 software developers and data experts.

Dynamically call a function

For the project I'm working on, I need to dynamically call one of several functions (which are dynamically named by asp.net). How do I call a function when I have the function name in a string? A case statement is not an option, because the function names are dynamic.
Expand|Select|Wrap|Line Numbers
  1. function function1() {
  2.    ...
  3. }
  4. function function2() {
  5.     ...
  6. }
  7. var functionName = 'function1'
  8.  
...what next?

How do I execute the function whose name is stored in functionName?

Thanks
Sep 24 '09 #1
3 3270
gits
5,390 Expert Mod 4TB
when the functions are declared in the window-scope then you might use:

Expand|Select|Wrap|Line Numbers
  1. window['yourFunctionName']();
to call the function.

kind regards
Sep 25 '09 #2
Thanks. I figured there was a pretty easy way to do it.
Sep 25 '09 #3
gits
5,390 Expert Mod 4TB
no problem ... in case you would have more questions just post back to the forum ...

kind regards
Sep 25 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Ola Fjelddahl | last post: by
2 posts views Thread by Joe | last post: by
8 posts views Thread by Falc2199 | last post: by
11 posts views Thread by Steven D'Aprano | last post: by
2 posts views Thread by Claire | last post: by
11 posts views Thread by onkar.n.mahajan | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.