Using a closure to execute a function in the future?
<p>I'm trying to use a closure (I think that's what it is..), I'd just like to execute a function with a local variable at some point in the future, like this:</p>

<pre><code>function boo() {
    var message = 'hello!';
    var grok = function() { alert(message); }
    foo(grok);
}

function foo(myClosure) {
    $.ajax({
        timeout: 8000,
        success: function(json) {
            myClosure();
        }
    }
}
</code></pre>

<p>I could get around this by using global variables and such, but would rather use something like the above because it at least seems a bit cleaner. How (if possible) do you do this?</p>

<p>Thanks</p>

<p>----------- Update --------------------</p>

<p>Sorry I wasn't clear - I was wondering if this is the correct syntax for the closure, I tried it out and it seems ok. Thank you.</p>
