Example of closure in "Javascript: The good parts"
<p>I am reading about closures in "Javascript: The Good Parts" book.</p>

<p>There is following example of using closures:</p>

<pre><code>var add_the_handlers = function (nodes) {
var i;
   for (i = 0; i &lt; nodes.length; i += 1) {
      nodes[i].onclick = function (i) {
         return function (e) {
            alert(i + ":" + e);
         };
      }(i);
   }
};
</code></pre>

<p>Is it correct example? Or much correct example would be following?</p>

<pre><code>var add_the_handlers = function (nodes) {
var i;
   for (i = 0; i &lt; nodes.length; i += 1) {
      nodes[i].onclick = function (idx) {
         return function (e) {
            alert(idx + ":" + e);
         };
      }(i);
   }
};
</code></pre>

<p>Variable i in the outer function and variable i in the inner function "nodes[i].onclick = function (i)" - it is two different variables. 
And third function accesses variable from second function, not from the outermost.<br>
Am I correct?</p>
