Last Updated: July 30, 2016
· manudwarf

underscorejs - use defer instead of setTimeout

We often have dirty 0ms setTimeout in our code. Although it perfectly works, it feels wrong to do it this way, that's why you can use _.defer() to do it :

_.defer(function() {
    console.log("Do something");

More at the underscore API:

2 Responses
Add your response

lol - what you're saying is replace: setTimeout(fn, 0) with setTimeout(fn, 1) --- defer simply sets 1ms delay

over 1 year ago ·


over 1 year ago ·