0

I'm wondering if it's possible to have a bunch of functions like:

function board_1(){

}
function board_2(){

}
function board_3(){

}

Then call the function like:

var num = 2;

board_+num();

I know you can do something with parameters, but that isn't going to work for me in this situation.

Cian Flint
  • 71
  • 10
  • 2
    You never need or want unknown variable names. Please use an object instead: `const funcs = {board_1(){}, board_2(){}, board_3(){}};` … `funcs["board_" + num]();`, or an array. – Sebastian Simon Aug 23 '18 at 14:38
  • 2
    You could do this, but it's a bad idea. A muich better solution would be to make a single function and pass in whatever arguments differentiate the logic between them. If you *have* to do it this way, put each function in an object, then call it by the name of that property, eg. `funcObject['board_' + num]();` – Rory McCrossan Aug 23 '18 at 14:38

0 Answers0