节流和去抖函数之间的区别 [英] Difference Between throttling and debouncing a function

查看:124
本文介绍了节流和去抖函数之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以给我一个简单的单词解释,说明为限速目的而限制和去除函数之间的区别。

Can anyone give me a in-simple-words explanation about the difference between throttling and debouncing a function for rate-limiting purposes.

对我来说两者似乎都做了同样的事情。我查看了这两个博客,找出:

To me both seems to do the same the thing. I have checked these two blogs to find out :

http://remysharp.com/2010/07/21/throttling-function-calls

http://benalman.com/projects/jquery-throttle-debounce-plugin/

推荐答案

简单来说:


  • 限制会延迟执行一个功能。它会减少多次触发事件的通知。

  • Debouncing 会将对函数的一系列顺序调用聚合成对该函数的单个调用。它确保为多次触发的事件发出一个通知。

  • Throttling will delay executing a function. It will reduce the notifications of an event that fires multiple times.
  • Debouncing will bunch a series of sequential calls to a function into a single call to that function. It ensures that one notification is made for an event that fires multiple times.

您可以直观地看到差异这里

You can visually see the difference here

如果您有一个被调用的函数 - 例如调整大小或鼠标移动事件发生时,可以调用很多次。如果您不想要这种行为,可以节流它,以便定期调用该函数。 Debouncing 意味着它会在一系列事件的结尾(或开始)被调用。

If you have a function that gets called a lot - for example when a resize or mouse move event occurs, it can be called a lot of times. If you don't want this behaviour, you can Throttle it so that the function is called at regular intervals. Debouncing will mean it is called at the end (or start) of a bunch of events.

这篇关于节流和去抖函数之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆