title: Accessing mutable variable in an event closure
body: <p>I am trying to use the <a href="http://craig.is/killing/mice" rel="nofollow noreferrer">mousetrap</a> Javascript plugin to handle some key strokes in a similar fashion, so I thought to code them up as follows:</p>
  <pre><code>    var keys = [ 'b', 'i', 'u'];
      for (var i=0; i &lt; 3; ++i) {
          var iKey = keys[i];
          var iKeyUpper = iKey.toUpperCase();
  
          Mousetrap.bind(
              [   'command+' + iKey,
                  'command+' + iKeyUpper,
                  'ctrl+' + iKey,
                  'ctrl+' + iKeyUpper],
              ( function( e ) {
                  console.log( &quot;you clicked: &quot; + i );
          } ) );
  
      }
  </code></pre>
  <p>But, obviously, <code>i</code> is mutable.  However, I am not sure how to write a closure where I am competing the event parameter in the response.  Suggestions on how to handle this situation?</p>