While solving a programming challenge, I wrote a function which was intended to take a function as an argument and return a function as well. The returned function was meant to execute the argument function (which was passed to first function). The function's code :-
function func1(f){
let func2 = function(){
if(/*a condition based on a global variable*/){
f();
}
}
return func2;
}
This is currently not working and it raises an Illegal Invocation Type Error
. I saw this question but I don't know how to relate it's answers to my code. So, my questions are :-
- Why isn't my code working?
- What can I do to make it work?
EDIT
I'm invoking the function like this :-
var someFunc = func1(alert);
someFunc("foo");
someFunc("bar");