Variable scope in anonymous function
<p>I'm trying to populate an array in JavaScript using an anonymous function in the jQuery <code>getJSON()</code> function as follows.</p>

<pre><code>$(document).ready(function() {

    function Link(url, title) {
        this.url = url;
        this.title = title;
    }
    var links = [];

    $.getJSON("http://reddit.com/r/programming/.json?jsonp=?", function(data) {
        $.each(data.data.children, function(i, item) {
            var title = item.data.title;
            var url = item.data.url;

            links.push(new Link(url, title));
        })
    });

    for(var i=0; i&lt; links.length; i++) {
        var output = "&lt;a href='" + k + "'&gt;" + links[k] + "&lt;/a&gt;";
        $('&lt;p&gt;' + link + '&lt;/p&gt;').appendTo('#content');
    }

});
</code></pre>

<p>But, when I hit the for loop, the links array shows up empty.  What's going on here?</p>
