Modify the function return for synchronous

2

Hello, I need to modify this function to use callback as a function return and not as a new function call via callback.

I need this in this way because I'm creating a generic method for deletion acknowledgments on the existing system. If I can not, it will give me a lot of work to do with the changes.

I'm using the JS BootBox library and the method is:

function Confirm(messageOfConfirmation){
    bootbox.confirm({
        message: messageOfConfirmation,
        buttons: {
            confirm: {
                label: 'Yes',
                className: 'btn-success'
            },
            cancel: {
                label: 'No',
                className: 'btn-danger'
            }
        },
        callback: function (result) {
            functionOfCallback(result);
        }
    });
}

And to reinforce and avoid understandings of duplicity in the question, here is an example of how I intend to use it.

function PodeExcluir(){
     if(Confirm("Tem certeza que deseja excluir?"){
        //Chamada de exclusão aqui
    }
}

I mean, today the system already uses the standard JS confirm but I need to change it.

    
asked by anonymous 14.12.2016 / 12:43

1 answer

2

A simple way to resolve this is to use your own callback .

Example:

function Confirm(messageOfConfirmation, functionOfCallback) {
    //nenhum alteração necessária
}

function PodeExcluir(){
     Confirm("Tem certeza que deseja excluir?", function(result) {
         //Chamada de exclusão aqui
     });
}

Understand that since JavaScript code is interpreted linearly in the browser, the use of elements for user interaction - with the exception of the default commit box - should be asynchronous, that is, using callbacks / * listeners, events, etc.

    
15.12.2016 / 01:12