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

Categories

0 votes
253 views
in Technique[技术] by (71.8m points)

weex如何支持setInterval()方法?

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


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

1 Answer

0 votes
by (71.8m points)

可以用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(){
          
        }])

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...