// 基本方法
export const basicFn = () => {
  const test = '通用方法测试'
  return test
}

// 函数防抖 使用方法
// xxx: debounce(function () {
//   console.log("拿到数据");
// }, 1000),
export const debounce = (fn, awaits) => {
  let timer
  return function() {
    // console.log('进入防抖')
    let context = this
    let args = arguments
    if (timer) {
      clearTimeout(timer)
      timer = null
    } else {
      timer = setTimeout(function() {
        fn.apply(context, args)
      }, awaits)
    }
  }
}

// 节流
export const throttle = (func, wait) => {
  // console.log('进入节流')
  let timeout
  return function() {
    let context = this
    let args = arguments
    if (!timeout) {
      timeout = setTimeout(() => {
        timeout = null
        func.apply(context, args)
      }, wait)
    }
  }
}
