The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Solved] Simpler way to write this snippet? Reply To: Simpler way to write this snippet?


The following snippet forces events to fully execute without interruption before firing again.

I am not sure what you’re trying to do, here. jQuery’s .stop() and .clearQueue() do completely different things (and neither seem to be what you are describing).

var a = 200;
var b = 0;
var c = 0;
var d =; // say, 1379985942942
if (d - c < b + a) {
c = d;

let’s look at this…

if( 1379985942942 - 0 < 200 +0 )
if( 1379985942942     < 200    )
if( false                      )


Is this supposed to be in a loop (might be implied by c = d)?

if( false ){ return; }

Won’t happen, so you assign c the value of d and start over. Then you assign c the value of 0 and run the comparison again – you have an infinite loop.

…I’m curious if there’s a cleaner approach to writing it

well, the only thing that jump out at me is that b is always 0, and so, never affects the value b + a in the comparison – you could leave it out.

But I think we need a bit more explanation about what you’re actually trying to do.