UNPKG

web-utils-super

Version:

前端函数库

21 lines (20 loc) 562 B
/** * @desc: 节流函数 每隔一段时间就执行一次,设置一个定时器,约定xx毫秒后执行事件,如果时间到了,那么执行函数并重置定时器 * @param {Function} func * @param {Number} wait * @return {Function} */ function throttle(func, wait) { let timeout = null return function () { let context = this let args = arguments if (!timeout) { timeout = setTimeout(() => { timeout = null func.apply(context, args) }, wait) } } } module.exports = throttle