javascript - Fastest debounce implementation -


In my application, I have some heavy functions in the scrolling event. To limit the frequency of execution, Using the method:

  var timeout; Document.addEventListener ("scroll", function () {explicit timeout (timeout); timeout = set timeout (function () {// some heavy code}, 200);});  

Is there a better way to do this? Is not set up from time to time to be very heavy to fire?

EDIT: What concerns me with the most memory usage - I think every settimeout is allocating something, it is a memory allocation from the Chrome timeline (this bella :):

< P> Enter image details here


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -