d-utils
Version:
d-utils
18 lines (17 loc) • 671 B
TypeScript
/**
* @description 函数节流
* @param { Function } fn 需要节流的函数
* @param { Number } t 节流时间,多久以后执行一次方法 单位ms
* @example
* // 在鼠标resize的过程中,1秒触发一次,如果resize了10秒相当于console.log('resize')只执行了10次
* window.onresize = throttle(function () {
* // es5 获取参数
* let arg = Array.prototype.slice.call(arguments)
* // es6 获取参数
* let arg1 = Array.from(arguments)
* console.log('resize-throttle', arg)
* console.log('resize-throttle', arg1)
* }, 1000)
*/
declare function throttle(fn: Function, t?: number): Function;
export default throttle;