how does closure work when declaring anonymous functions in javascript(jquery) calls?
<p>In this function:</p>

<pre><code>var x = {
  getStuff : function(){
     var i = 0;
     $.getJSON('/url.json', {}, function(data){
        $.each(data, function(key,val){ 
          alert(i);
        });            
     });
  });
}
</code></pre>

<p>So am I understanding correctly that the anonymous functions declared for the 2 jquery calls (.getJSON, .each) both have access to the parent function(getStuff) due to closure? </p>

<p>Does that mean that the anonymous functions are being declared in that location are within the scope chain of its parent so they have access to the parents variables?</p>
