Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

javascript - 节流和反跳功能之间的区别(Difference Between throttling and debouncing a function)

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://remysharp.com/2010/07/21/throttling-function-calls) http://benalman.com/projects/jquery-throttle-debounce-plugin/(http://benalman.com/projects/jquery-throttle-debounce-plugin/)   ask by bhavya_w translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To put it in simple terms:(简单来说:)

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(您可以在这里直观地看到差异) 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.(防弹跳意味着在一系列事件的结尾(或开始)调用它。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...