I haven't found an answer to the problem I am trying to understand. I would be thankful if someone can help me: I am working on a JavaScript project and I need to pass an event function as a parameter for a callback function. Is there a way to get this?
I know that this works fine:
function callback(){
alert("called!");
}
function trigger_callback(message, callback){
alert(message);
callback();
}
trigger_callback("I will call a function", callback);
But what I need is something like this:
trigger_callback("I will focus an input", $("#input").focus);
I get the error:
TypeError: this._focus is undefined
So far, I've been using:
trigger_callback("I will focus an input", function(){$("#input").focus();});
I need a simpler way to do it. Also, can someone please explain why this fails?