Is there a way to name a function base on a string?
Scenario:
I need to create an array of funcs. For this I'm looping through an array of objects, and the idea would be to name the function based on the object.name.
Ideally for objects named a and b, funcs would have [func1_a, func2_a, func1_b, func2_b]
Example:
let types = [
{
'name': 'a',
'key': 'a_key',
'value': 'this is a value',
},
{
'name': 'b',
'key': 'b_key',
'value': 'this is b value',
}
];
let funcs = [];
for (const type in types) {
test.push(
function func1_{type.name} {
// do something with type.key and type.value
},
function func2_{type.name} {
// do something with type.key and type.value
}
)
}
Problem
I know function func1_{type.name} is not correct, thus I'm trying to find the way to do this. Any ideas? Or something like this is even possible?
Note: most of the resources I found are how to call a function based on a string, but nothing on how to name/create a function based on a string.
Thanks in advance!