Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

63.throttle #63

Open
webVueBlog opened this issue Sep 8, 2022 · 0 comments
Open

63.throttle #63

webVueBlog opened this issue Sep 8, 2022 · 0 comments

Comments

@webVueBlog
Copy link
Member

// 节流
// 原理:事件被频繁触发时,事件回调函数会按照固定频率执行,比如1s 执行一次,只有上个事件回调被执行之后下一个事件回调才会执行
// 事件回调函数
// wait 事件回调的执行频率,每wait毫秒执行一次

function throttle(fn, await = 500) {
 let timer = null
   
 return function(...args) {
  if (timer) return
  timer = setTimeout(() => {
    fn.apply(this, args)
    timer = null
  }, await)
 }
}




Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant