setInterval、clearInterval的回调函数,实现函数间调用的先后顺序

定义:

var waitUnitil=function (untillCallBack, nextStepCallBack, count) {
            if (count == null) {
                count = 0;
            }
            var timer = setInterval(function (ucb, ncb, c) {
                var checkResult = ucb();
                if (c == 100 || checkResult) {
                    clearInterval(timer);
                    ncb();
                    interval = null;
                    return;
                } 
                console.log((c++) + "," + checkResult);
            }, 10, untillCallBack, nextStepCallBack, count);
        }

  

 调用:

            waitUnitil(
                function () {
                    return walletContactInfoCreator.getEle$("#AddressInfo_City").find("option").length > 1;
                },//终止条件
                function () {
                    walletContactInfoCreator.getEle$("#AddressInfo_City").val(walletContactInfoCreator.entityV.AddressInfo.City).change();
                }//下一步
            )    

  

猜你喜欢

转载自www.cnblogs.com/panpanwelcome/p/10846711.html