/*
 * @Author: Billy
 * @Date: 2022-03-17 11:49:58
 * @LastEditors: Billy
 * @LastEditTime: 2022-03-17 12:01:56
 * @Description: 输入框优化函数
 */

/**
 * @description 防抖函数
 * @param {Function} fn 回调
 * @param {number} delay 延迟时间(毫秒)
 * @returns 
 */
function debounce(fn, delay) {
    let timerId;
    return function (...args) {
        if (timerId) clearTimeout(timerId);
        timerId = setTimeout(() => {
            fn.apply(this, args) // setTimout会发生this隐式丢失；改变this指向为调用debounce所指的对象
        }, delay);
    }
}

export default {
    debounce
}