Taro中可以使用Loadash吗
-
想使用Loadash中的debounce
-
人肉写 ?
/** * @description: 函数防抖 当持续触发事件时,一定时间段内没有再触发事件, * 事件处理函数才会执行一次,如果设定的时间到来之前,又一次触发了事件,就重新开始延时。 * 使用:注意!不能使用箭头 函数 * @param {Function} fn 执行的函数 * @param {number} interval 延迟时间 * @return: function */ export const debounce = function(fn: Function, interval: number = 1000, self?) { let timer: any; // 计时器 return function() { clearTimeout(timer); // 清空上次未完成的计时器 let _this = self || this; timer = setTimeout(() => { fn.call(_this, arguments); }, interval); }; };