How do I send a condition test to a Javascript function and not only it's result?
<p>I had the idea about making a small jQuery plugin but there's something I don't know how to do it without having to rely on <code>eval</code>.</p>

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

<pre><code>            var testMe = 1;

            $.extend({
                once : function( condition, duration, callback) {
                    window[ "once" ] = window.setTimeout(function() {
                        if ( condition )
                        {
                            callback.apply();

                            window.clearTimeout( window[ "once" ] );
                        } else {
                            window[ "once" ] = window.setTimeout( arguments.callee, duration * 1000 );
                        }
                    }, duration * 1000 );
                }
            });

            $.once(testMe == 2, 5, function() {
                alert("Match!");
            });
</code></pre>

<p>It looks like when <code>$.once()</code> is being called, the first parameter is then evaluated and only it's value at this time is sent to the condition parameter. The only way I found is to send it as a string:</p>

<p><code>$.once("testMe == 2" ...</code> and use <code>if ( eval( condition ) )</code></p>

<p>Is there another way withing the use of <code>eval</code> ?</p>

<p>Thank you.</p>

<p><strong>Edit: here is the a final version of the plugin:</strong></p>

<pre><code>            var testOne = 1,
                testTwo = 1;

            $.extend({
                once : function( name, conditionFn, duration, callback) {
                    if ( typeof duration ==  "function" )
                    {
                        callback = duration;
                        duration = 5;
                    }

                    window[ "once" + name ] = window.setInterval(function() {
                        if ( conditionFn() )
                        {
                            callback();

                            window.clearInterval( window[ "once" + name ] );
                        }
                    }, duration * 1000 );
                }
            });


            //Examples
            $.once("testOne", function() {
                return testOne == 2
            }, 2, function() {
                alert("testOne == 1");
            });

            $.once("testTwo", function() {
                return testTwo == 2
            }, 2, function() {
                alert("testTwo == 1");
            });
</code></pre>
