How do you make an event listener that detects if a boolean variable becomes true?

前端 未结 7 2007
-上瘾入骨i
-上瘾入骨i 2020-12-31 19:52

For example, I have var menu_ready = false;. I have an ajax function that sets menu_ready to true when the ajax stuff is done:

//se         


        
相关标签:
7条回答
  • 2020-12-31 20:48

    There is no cross-browser (cross-platform) event which gets that job done. There are some pretty specific mechanisms to watch objects propertys for instance, but nothing to watch out for booleans (imo).

    You want to execute a callback function aswell at the time you're setting that variable to true. You can also apply some jQuery sugar:

    function myCallbackReference() {
        alert('yay');
    }
    
    $('#foobar').load('/some/code', function() {
        menu_ready = true;
    }).done( myCallbackReference );
    
    0 讨论(0)
提交回复
热议问题