I'm trying to define a function that should call a(nother) function that is passed as parameter of the main function.
function showMessage(title, text, button, callback) {
console.log(title, text, button);
if (typeof (callback) != "function") {
function callback() {};
alert("converted callback");
}
$("div").click( function() {
callback();
});
}
function myfunction() {
alert("function!");
}
showMessage("title", "text", "button", myfunction() );
Demo: http://jsfiddle.net/XvE8D/1/
The problem is that when showMessage()
function is called, myfunction()
is called istantly.
How can I fix the problem?