I tried posting this the other day, but my post didn't come through
for some reason. I've got a snippet of code that will allow you to
either throttle or debounce a function, in multiple ways. Granted, my
implementation does not use the Function prototype, but that would be
trivial to implement.
(And please don't mind the "jQuery" in the name, it doesn't require
jQuery in any way, it just uses it as an optional namespace!)
http://benalman.com/projects/jquery-throttle-debounce-plugin/
Either way, if you find any of the code useful, feel free to use it!
- Ben
On Apr 23, 1:28 pm, Andrew Dupont <
goo...@andrewdupont.net> wrote:
> I like this. I don't particularly care what we call it.
>
> Too late for 1.7, naturally, but perhaps 1.7.1 or 1.8...
>
> Cheers,
> Andrew
>
> On Apr 23, 2010, at 10:15 AM, Mislav Marohnić wrote:
>
>
>
>
>
> > On Fri, Apr 23, 2010 at 15:00, Titi Alailima <
tigreti...@gmail.com> wrote:
>
> > "debounce" is a technical term, and it refers to the very case that you are trying to handle.
>
> > Thanks, Titi, for the insightful explanation.
>
> > Here is how I would implement a real throttle method:
>
> > Function.prototype.throttle = function(t) {
> > var timeout, scope, args, fn = this, tick = function() {
> > fn.apply(scope, args)
> > timeout = null
> > }
> > return function() {
> > scope = this
> > args = arguments
> > if (!timeout) timeout = setTimeout(tick, t)
> > }
> > }
>
> > It's really just a twist on the original method in a way that it fires every `t` milliseconds, and calls in-between do nothing except update the scope and arguments. If the first argument is an event object, you definitely want the last event object of the series rather than the first one.
>
> > --
> > You received this message because you are subscribed to the Google Groups "Prototype: Core" group.
> > To post to this group, send email to
prototy...@googlegroups.com
> > To unsubscribe from this group, send email to
prototype-cor...@googlegroups.com
> > For more options, visit this group athttp://
groups.google.com/group/prototype-core?hl=en
> For more options, visit this group athttp://
groups.google.com/group/prototype-core?hl=en