1.0.1 • Published 1 year ago
zwlcommonutils v1.0.1
throttle and debounce
Throttle and debounce functions.
Install
npm install zwlcommonutils --save
Usage
debouncingA
import { debouncingA, debouncingB, throttleA, throttleB } from 'zwlutils';
const throttleFunc1 = debouncingA( // or (debouncingB, throttleA, throttleB)
(num) => {
console.log('num:', num);
},
1000);
throttleFunc1()
// ================================================================
function fn(e){
console.log(e)
}
const throttleFunc2 = debouncingA(fn,1000) // or (debouncingB, throttleA, throttleB)
throttleFunc2()
// debouncingA 防抖 立即执行
// debouncingB 防抖 非立即执行
// throttleA 节流 立即执行
// throttleB 节流 非立即执行
API
debouncingA(callback, delay)
Returns: Function
debouncingA, debouncingB, throttleA, throttleB 都按此顺序传参
callback
Type: Function
A function to be executed after delay milliseconds. The this
context and all
arguments are passed through. (this上下文和参数都已绑定callback)
delay
Type: Number
延迟的毫秒数