Based on the JavaScript example below, is there a way to pass a reference to function f to the promptForProceed function and have it conditionally executed in promptForProceed?
Could you also do this if the ffunction took some parameters (ie: f(a, b, c) { ... })?
function f() {
//Do stuff..
}
function promptForProceed(myFunction) { // <------ PASS FUNCTION AS PARAMETER
$("#div-dialog-proceed").dialog({
modal: true,
buttons: {
"Stay on current page": function () {
$(this).dialog("close");
},
"Continue": function () {
$(this).dialog("close");
myFunction(); // <--------- CALL FUNCTION
}
}
});
}
Update: Think I like the option of using an anonymous function parameter:
promptForProceed(function() { //Do stuff like call f(a,b,c) });
Yes, but you should probably not name both of them
for it will be confusing what is going on. The line you calledf()on is calling the parameter, not the functionf(unless that’s what you passed)To pass parameters, pass
promptForProceed(myFunction, a, b, c)and then call withmyFunction(a, b, c)