简体   繁体   中英

Can I simplify these nested javascript “if” statements into one?

So I have two variables, animationFlag and ajaxFlag. I also have a function setup that returns true or false based on browser support of transitions. That I'd like to happen is that it only runs this fadein function if ajaxFlag is true AND animationFlag is true. But in a browser without transition support, animationFlag will never become true so I need to check if it supports transitions, then check for the ajaxFlag only if transitions aren't supported. I tried separating them with || and && in different combinations, but I really need this nesting.

A single if statement would be WAYYYY nice, so, is it possible to combine that into one? Thanks!

    function checkDone() {
        if (!supportsTransitions) {
            if (ajaxFlag) {
                setTimeout(function(){
                    fadeInModal();
                },100)
            }
        } else {
            if (ajaxFlag && animationFlag) {
                setTimeout(function(){
                    fadeInModal();
                },100)
            }
        }
    }

This should work

if (ajaxFlag && (animationFlag || !supportsTransitions)) {
    // ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM