Some questions about js debounce function

encountered a very confusing problem, because it needs to be used in the development of the shake,
so I wrote a function.

export function debounce(func, wait) {
  var timer
  return function (){
    console.log(timer)
    clearTimeout(timer)
    timer = setTimeout( function () {
      func(arguments)
    }, wait)
  }
}

is called in the place of the call:
onAfterChange= {debounce (this.onAfterChange.bind (this), 5000)}

then executed twice, this.onAfterChange. And timer was printed on it, and undefine was printed twice.

Jun.19,2021

doesn't know how you call it. Method is normal and will only be executed once (although this is not de-dithering but indefinitely delayed execution).

Menu