debounce function in underscore

2019-08-17 09:19发布

问题:

I am trying to use the debounce function for setting automatic logout for my application. My understanding is that debounce function will fire the function after the 30 seconds if my application not used. I tried to read the documentation of debounce and feel like I have done the exact something. Am i missing out something? or Is my understanding totally wrong?

var logout_debounce = _.debounce(debounceHandler, 30);

function debounceHandler() { location.reload(); }

$("body").on("mousemove", logout_debounce);

回答1:

The time is in milliseconds so you would need to do 30 * 1000



回答2:

That 30 is milliseconds, if you want it to be fired after 30 seconds ; you must use 30*1000 = 30000