One solution will be ...
function a () { b( function () { // do x }, function () { // do y }); } function b ( fn1, fn2 ) { $( "#anElement" ).dialog({ title: "This is a Dialog", buttons: { "Yes": function () { //do some stuff $( this ).dialog( "close" ); fn1(); }, "Cancel": function () { //do some stuff $( this ).dialog( "close" ); fn2(); } } }); }
So you pass two functions to b
. The first is activated if the "Yes" button is activated, and the second function is activated if the "Cancel" button is activated.
This pattern allows you to define behavior directly inside function a
instead of adding it to function b
.
source share