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

<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>
原文地址:https://www.cnblogs.com/wrongcode/p/10968581.html