Is there a way nest functions and pass them as a parameter? I have this 2 functions:
function mayus(string) {
return string.toUpperCase();
}
function removeA(string) {
return string.replace(/A/g, "");
}
and I want to apply them in 2 different ways
function stringHandler1(stringID) {
var newString = mayus(removeA(getString(stringID)));
return newString;
}
function stringHandler2(stringID) {
var newString = removeA(mayus(getString(stringID)));
return newString;
}
The 2 stringHandlers return slightly different strings, but they are fairly similar. Is there a way to use one string handler that takes 2 parameters (the stringID and the operation)
function stringHandlerINeed(string, operation) {
var newString = operation(string);
alert(newString);
}
I want to do something like
stringHandlerINeed("516af2", mayus(removeA))
Update: I marked jJ' as the answer because it doesn't require me to change any of the functions I already have, and it's the concept I was looking for, but this answer by juvian is so simple makes me wish I had come up with it.