lvil
lvil

Reputation: 4326

Dealing with message box asynchronious

There is a function that returns true/false only after a button on messageBox is clicked dealing with extjs messagebox asynchronious.

function mayGo(){
var clicked=false;
var may=false;

        Ext.Msg.show({
            title:'del?',
            msg: 'the items will be deleted?',
            buttons: Ext.Msg.YESNO,
            fn: function (button){
                    if (button=='yes'){clicked=true;may=true;}
                    if (button=='no'){clicked=true;may=false;}
                }
        });

        newf();
        function wait(){
alert("alert2");
                var t=setTimeout(newf(), 5000);


        }
        function newf(){
            if (!clicked){alert("alert1");wait();}
        }
        return may;}

The function continues executing. What is wrong? Why the timeout doesn't work?

Upvotes: 0

Views: 184

Answers (1)

BGerrissen
BGerrissen

Reputation: 21680

remove parens from

var t=setTimeout(newf(), 5000);

so you get:

var t=setTimeout(newf, 5000);

newf was executed, so you where actually setting a timeout on the return value of newf. It was equivalent to:

var und = newf(); // returns undefined
var t = setTimeout( und , 5000 ); // wont work.

Upvotes: 1

Related Questions