title: How to avoid access mutable variable from closure
body: <p>I have some code like this:</p>
  
  <pre><code>for(var id=0; id &lt; message.receiver.length; id++){
     var tmp_id = id;
     zlib.gzip(JSON.stringify(message.json), function(err, buffer){
                          ...
     pushStatusPool[message.receiver[tmp_id]] = null; // fix memory leak
     delete pushStatusPool[message.receiver[tmp_id]];
     ...
     });
  }
  </code></pre>
  
  <p>And I got a warning that using <code>tmp_id</code> in closure may cause problem because it is a mutable variable.</p>
  
  <p>How could I avoid that? I mean how could I send an immutable variable to callback since this is a for loop and I can not change code of <code>zlib.gzip</code>? Or in other words, how could I pass a argument to a closure?</p>