首页 > 其他 > 详细

30秒内限制函数只被调用一次

时间:2019-06-03 17:39:15      阅读:91      评论:0      收藏:0      [点我收藏+]
<script>
  function throttle (func, duration) {
      // duration 以秒计
      let last
      return function () {
           let now = Date.now()
           if (last && (now - last) < duration * 1e3) return
           last = now
           func.apply(this, arguments)
      }
  }

  var aa = function(a,b){
    console.log(a+b)      
  }

  var aa = throttle(aa, 30)

  aa(2, 3)
</script>

 

30秒内限制函数只被调用一次

原文:https://www.cnblogs.com/wrongcode/p/10968581.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!