# Is it possible to use a variable in the name of a function?

**URL:** <https://forum.kirupa.com/t/is-it-possible-to-use-a-variable-in-the-name-of-a-function/61014>\
**Category:** flash\
**Created:** [August 14, 2004, 11:28pm UTC](https://forum.kirupa.com/t/is-it-possible-to-use-a-variable-in-the-name-of-a-function/61014 "2004-08-14T23:28:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsears](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@jsears](https://forum.kirupa.com/u/jsears)\
**Post date:** [August 14, 2004, 11:28pm UTC](https://forum.kirupa.com/t/is-it-possible-to-use-a-variable-in-the-name-of-a-function/61014/1 "2004-08-14T23:28:02Z")

</div>

I’d like to have a number of different functions named something like:  
“function1”, “function2”, “function3”, all the way up to function100.

I’d like to be able to call them by adding the the number as a variable. For example:

type = 2;  
function+type();

Which would call function2. I’m trying to avoid a huge if/else statement by only calling the functions I need.

Is this even possible? Can a function be called if part of the function name is a variable? Is there another way to join “function” with the variable and then call it? Thanks!

-John

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 14, 2004, 11:38pm UTC](https://forum.kirupa.com/t/is-it-possible-to-use-a-variable-in-the-name-of-a-function/61014/2 "2004-08-14T23:38:24Z")

</div>

see  
[http://www.kirupaforum.com/forums/showthread.php?t=12082](http://www.kirupaforum.com/forums/showthread.php?t=12082)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 15, 2004, 12:11am UTC](https://forum.kirupa.com/t/is-it-possible-to-use-a-variable-in-the-name-of-a-function/61014/3 "2004-08-15T00:11:08Z")

</div>

Or simply:

type = 2;  
\_root"function"+type;
