jiangchengfeiyi-xiaochengxu/uni_modules/zp-mixins/utils/debounce.js

18 lines
322 B
JavaScript
Raw Normal View History

2025-04-02 15:45:33 +00:00
/**
* 防抖
* @param {Object} scope //引用的this发现不显式传this拿不到。
* @param {Object} fn
* @param {Object} delay
*/
let t = null
const debounce = function(scope, fn, delay) {
if (t !== null) {
clearTimeout(t)
}
t = setTimeout(() => {
scope[fn]()
}, delay)
}
export default debounce