# 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/119442
**Category:** Uncategorized
**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/119442 "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/119442/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: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### 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/119442/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: ![dangerskew](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@dangerskew](https://forum.kirupa.com/u/dangerskew)
#### 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/119442/3 "2004-08-15T00:11:08Z")

</div>

Or simply:

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