I just want to assign a variable to a function so it can be invoked later but in this fiddel the function is invoked every time I press button ‘invoke’
Should it not just assign the function to the varialbe ‘fun’ and not call the alert ?
fiddle : http://jsfiddle.net/vkvUR/
code :
$("#button").click(myFun);
<input name="Button3" type="button" value="Invoke" id="button">
function myFun(myarg){
var fun = alert(myarg);
}
function myFunParam(myFun){
if (typeof myFun === "function")
myFun('foo'); // alerts "foo"
}
You need to assign an anonymous function to
funcontaining youralertcall.Change:
To:
http://jsfiddle.net/Curt/vkvUR/1/
And heres a version calling
fun():http://jsfiddle.net/Curt/vkvUR/2/