3 ms·
http://underscorejs.org/#throttle http://underscorejs.org/#throttle
by pyrotechnick 14y ago
http://underscorejs.org/#throttle http://underscorejs.org/#throttle
- gliese1337 14y agoAnd if you don't want to add dependency on a whole framework just for that little bit of functionality? It's useful to know how to implement it on its own.
- vmind 14y agoWell the example given is bugged, as if you make updates at 0 and 50, then it never fires the function at 100 for the change that occurred at 50. If I didn't want to rely on the whole framework, I'd copy and paste the tested implementation (and dependencies) in underscore. Not that it's bad to know how to do it yourself, but I'd make sure my implementation was sound before sharing it as advice.
- WiseWeasel 14y agoUnderscore is tiny, and there are lots of other goodies you'll probably want to use in there if you look, like _.each(), _.defer(), _.pluck(), _.escape(), and so many more; totally worth it. I installed underscore for backbone, and I have a hard time imagining life without it now, even if I didn't use backbone.
- dagw 14y agoWhen I'm writing actual web sites I always include underscore. However when writing libraries that I want to distribute on their own I don't want to force unnecessary third party dependencies on end users if it can be avoided. In those cases I have pulled out a single underscores function that I happened to need.
- jashkenas 14y agoThe current implementation of Underscore's debounce and throttle functions (both useful) is available here: https://github.com/documentcloud/underscore/blob/master/underscore.js#L618-664 https://github.com/documentcloud/underscore/blob/master/unde...
- rthprog 14y agoOP here. I updated the post with a link to underscore's annotated source for debounce and throttle. Thanks for the tip.
- bicknergseng 14y agoHad no idea _ had debounce. Just wrote my own the other day... in CoffeeScript no less. Thanks for being awesome!