// -防抖
export function debounce(fn, wait) {
    let delay = wait || 500
    let timer
    return function() {
        let args = arguments;
        if (timer) {
            clearTimeout(timer)
            console.log('debounce')
        }
        let callNow = !timer
        timer = setTimeout(() => {
            console.log('debounce send')
            timer = null
        }, delay)
        if (callNow) fn.apply(this, args)
    }
}

// -节流
export function throttle(fn, wait) {
    let delay = wait || 500
    let timer = null
    return function() {
        if (timer) {
            console.log('throttle');
            return
        }
        timer = setTimeout(() => {
            console.log('throttle send');
            fn.apply(this, arguments)
            timer = null
        }, delay)
    }
}