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

Javascript: throttle and debounce #1

Open
wxyudl opened this issue May 8, 2017 · 0 comments
Open

Javascript: throttle and debounce #1

wxyudl opened this issue May 8, 2017 · 0 comments

Comments

@wxyudl
Copy link
Owner

wxyudl commented May 8, 2017

throttlingdebouncing 都可以对执行的函数进行速率限制。

throtting:在一段时间内,对调用函数的最大次数进行限制,比如:在100ms内最多执行一次该函数。

举个例子,如果你的函数会在10s内执行1000次,比如触发scroll事件,这时候性能开销就比较大,我们可以使用throttle进行控制,让函数每100ms执行一次,这样,10s内最大执行的次数为100次,有效减少了性能开销。
throttle

debouncing:经过一段时间以后才执行相应的函数。并且该函数只执行一次,比如:100ms以后才执行和这个函数。

举个例子:如果你的函数会在10s内执行1000次,比如触发scroll事件,当我们加上debounce的特效后,设置经过100ms后执行,Duang的一下,函数不会再这10s内执行了,相反,它会在事件结束后开始算起,经过100ms执行,也就是说在10.1s执行的该函数。
debounce

原文:http://youthol.top/2016/05/11/javascript-throttle-and-debounce/

扩展:http://hackll.com/2015/11/19/debounce-and-throttle/

@wxyudl wxyudl changed the title javascript: throttle and debounce Javascript: throttle and debounce May 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant