I have a foo function:
var foo = function(input) {
console.log(input)
}
And a bar function:
var bar = function(fn, condition) {
if (condition) {
fn();
}
}
I would like to pass foo as an argument of bar like: bar(foo, true);
The problem is that foo must be called executing a parameter. If I use bar(foo('param'), false);, foo will be executed before bar starts and check the condition.
Is there a better solution in JavaScript syntax?
I know that I could modify my bar function to the following, but I don't want to modify the bar implementation:
var bar = function(fn, fnParam, condition) {
if (condition) {
fn(fnParam);
}
}