Javascript: How do I tweak my debounce function to take an IF conditional?
<p>I found a bug, and tracked it down.<br>
You can <a href="http://jsfiddle.net/CTcZ9/" rel="nofollow"><strong>see a simplified example of my code here</strong></a>.</p>

<p>As it turns out, I need to debounce my <code>if()</code> statement rather than debouncing the function itself.<br>
I'd like to keep the debounce as a standalone function, but I'm not sure then how to pass the conditional in.</p>

<p>Any pointers?</p>

<p>Here's the code:
</p>

<pre><code>var foo = function(xyz) {
    alert(xyz);
};

function setter(func, arg1, arg2) {
    return {
        fn: func,
        arg1: arg1,
        arg2: arg2
    };
}

function debounce(someObject) {
    var duration = someObject.arg2 || 100;
    var timer;
    if (timer) {
        clearTimeout(timer);
    }
    timer = setTimeout(function() {
        someObject.fn(someObject.arg1);
        timer = 0;
    }, duration);
}

var toggle = true;

if (toggle) {
    debounce(setter(foo, 'The best things in life are worth waiting for.', 1250));
} else {
    foo('Instant gratification is sweet!!');
}
</code></pre>
