jashkenas / underscore

JavaScript's utility _ belt
https://underscorejs.org
MIT License
27.29k stars 5.53k forks source link

Why debounce debounce asap case expect this answer? #2987

Closed manyuemeiquqi closed 11 months ago

manyuemeiquqi commented 11 months ago

Why is the expected value for this test case 2? From my perspective, this code runs at intervals of 16, 32, 48, and 80, all of which are smaller than the wait value of 64. Why is the expected value 2 in this case?

debounce-case

jgonggrijp commented 11 months ago

Hi @manyuemeiquqi, kudos for noticing this detail and thank you for reaching out.

The 80 ms delay is on top of the 48 ms delay; the call to _.delay is nested inside another _.delay. So the actual times are 16, 32, 48 and 128 ms, with the final interval being a full 80 ms.

I will close this as answered, but please feel free to discuss.