You can do so with many different solutions:
Asynchronousity
function confirm(message) {
return new Promise(resolve => swal({
title: "Are you sure?",
text: message,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if (isConfirm) {
resolve(true);
} else {
resolve(false);
}
});
}
(async() => {
if (await confirm("You can no longer restore your file afterwards")) myFunction()
})();
In this code, we use a Promise to send the data outside of the confirmation function inside swal.
Directly Substituting myFunction
function confirm(message, myFunction) {
swal({
title: "Are you sure?",
text: message,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
closeOnConfirm: false,
closeOnCancel: false
},
(z) => { myFunction(Boolean(z)) }
});
}
confirm("You can no longer restore your file afterwards",(...args){
myFunction([...args]);
});
Because the isConfirm is already returning something that can be differed by true and false, we can directly put myFunction inside the Swal, so you simply have to run the confirm and add a parameter function to run the myFunction in a separate method, yet still obtaining the working results.
I advise you to use the 2nd method because it keeps things synchronous, and will save you time converting code to asynchronous functions.