0
Having a variable number of arguments and a generic function. I want to do something like:
f(g,vetorArgs){
return ()=>{
//...codigo arbitrario
g(vetorArgs[0],vetorArgs[1],vetorArgs[2],...,vetorArgs[n])
//...mais codigo arbitrario
}
}
In short the problem is that I need to call a function g
within a function f
however the function g
is generic and can have an indefinite amount of arguments from 1 to n
My doubt is how to transform all the elements of vetorArgs
in arguments to the function g
.
The only thing I could think of was to concatenate the arguments and use eval
.
f(g,vetorArgs){
strAux = ''
vetorArgs.forEach(arg => {
strAux = strAux + ',' + arg
})
strArgs = strAux.substring(1)
strExec = 'g('+strArgs+')'
eval(strExec)
return ()=>{
//...codigo arbitrario
eval(strExec)
//...mais codigo arbitrario
}
}
[Solved]
With the help of @Luiz Felipe I managed to reach the condition I wanted Upshot:
f(g,vetorArgs){
return ()=>{
//...codigo arbitrario
g(...vetorArgs); /* ou g.apply(null,vetorArgs)*/
//...mais codigo arbitrario
}
}
In my case there is already a function defined
f(a,b,c)
and anotherg(a,b)
and I want to be able to call inside an Encapsulator 
 function;encapsuladora (functionGenerica,vetorArrays){functionGenerica(vetorArrays[0],...,vetorArrays[n])}
f(...vetArgs)
and theg(...vetArgs)
– le314u
@le314u, I edited the answer.
– Luiz Felipe
Okay, please see if it’s more understandable.
– le314u
In the case that you mentioned at the end, my first implementation was trying to replicate ( even though I didn’t want to), after its explanation I managed to reach my goal of fact that was to encapsulate a function that performs another using the Rest parameter
– le314u