debounce function in underscore

2019-08-17 08:59发布

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);

2条回答
小情绪 Triste *
2楼-- · 2019-08-17 09:45

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

查看更多
forever°为你锁心
3楼-- · 2019-08-17 09:46

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

查看更多
登录 后发表回答