setTimeout执行完之后调用回调函数实例

demo: function(callback, delay=2000){
        this.status = false;
        setTimeout(function(){
            this.status = true;
        }, delay);
        let timer = setInterval(function(){
            if(this.status){
                clearInterval(timer);
                delete this.status;
                if (typeof callback == 'function') {
                    callback();
                }
            }
        },500);
    },

评论

评论正在提交中...请稍后
评论提交成功...