I'm building a fairly large JavaScript library made of hundreds of functions. Each function has a certain number of parameters, sometime not known at design time. I need to pipe every function parameter through some kind of parameter cleanUp()
function. I could do something like that:
function myFunction(param1, param2, ..., paramN) {
var param1 = cleanUp(param1);
var param2 = cleanUp(param2);
...
var paramN = cleanUp(paramN);
// Function's implementation goes here
}
function cleanUp(param) {
// Cleanup code goes here
return cleanParam;
}
But that would be quite verbose and repetitive (remember, I have hundreds of these functions).
My question is: what would be the best way to transparently pipe all the function's parameters through the cleanUp
function, either with inheritance, or anything more appropriate. I know that I can use the arguments
variable to access all the functions' parameters, but I would like the cleanup to happen outside of the functions themselves, into some other function that my functions could "inherit" from.
Note: within all the functions, parameters must keep their original names for readability purposes.