Reputation: 50
function fun (a, b) {
console.log(a + ' ' + b);
return a == b;
}
function test(condition) {
for(let i = 0; i < 1; i++) {
if(condition()){
break;
}
}
}
How can we pass function fun as an argument inside function test with the argument a and b (a and b are variable). writing test(fun('a', 'b'));
is resulting in an error.
Upvotes: 0
Views: 81
Reputation: 2691
You can use a closure
like this:
test(function(){ return fun('a', 'b'); });
Upvotes: 1