throttle.js 574 B

123456789101112131415161718192021
  1. const _my = require("../../../__antmove/api/index.js")(my);
  2. const wx = _my;
  3. const throttle = function(func, duration) {
  4. let start = 0;
  5. return function() {
  6. let that = this;
  7. let now = Date.now();
  8. if (now - start > duration) {
  9. func.apply(that, arguments);
  10. start = now;
  11. } else {
  12. // wx.showToast({
  13. // title: `您的操作太频繁啦,请在${Math.ceil(duration/1000)}秒后再试哦~`,
  14. // icon: 'none'
  15. // })
  16. }
  17. };
  18. };
  19. module.exports = {
  20. throttle
  21. };