Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

weex支持了setTimeout(),直接使用setInterval()不行?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
254 views
Welcome To Ask or Share your Answers For Others

1 Answer

可以用setTimeout模拟setInterval,效果更好。

/**
* @param {function} 回调
* @param {Number} 间隔
* @param {Object} 额外参数
*/
interval: function(func, wait, arg){
        var self = this
        var inter = function(){
          if(self.timeRemain != arguments[0][0]){
            func.apply(null, arguments)
            setTimeout(inter, wait, arg)
          }
          else {
            func.apply(null, arguments)
            arguments[0][1] && typeof arguments[0][1] == 'function' && arguments[0][1].call(null)
          }
        }
        setTimeout(inter, wait, arg)
      }
      
this.interval(function cb(){/*做点事情*/}, 1000, /*参数传递*/[0, function(){
          
        }])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...