util.js

// 防抖節流 防止重復點擊 function throttle(fn, gapTime) { if (gapTime == null || gapTime == undefined) { gapTime = 1500 } let _lastTime = null // 返回新的函數 return function () { let _nowTime = + new Date() if (_nowTime - _lastTime > gapTime || !_lastTime) { fn.apply(this, arguments) //將this和參數傳給原函數 _lastTime = _nowTime } } } module.exports = { throttle: throttle }
index.js

//開頭 const util = require('../../utils/util.js') //某個方法 withdraw: util.throttle(function (e) { }, 1000),