Make an object a method constant instead of a closure value in JavaScript/coffeescript
<p>I have the following JS:</p>

<pre><code>for (k in tools) {
  tool = tools[k];
  this["switch_to_" + tool.name] = (function(_this) {
    return function() {
      return _this.switch_tool(tool);
    };
  })(this);
}
</code></pre>

<p>Generated from this coffeescript:</p>

<pre><code>for k,tool of tools
  @["switch_to_#{tool.name}"] = =&gt;
    @switch_tool(tool)
</code></pre>

<p>What this is supposed to do is generate instance methods for switching between tool objects. Instead of <code>tool</code> referencing each distinct tool object with each distinct <code>switch_to_</code> method is called, it ends up referencing whichever value of <code>tool</code> is left over inside the closure. </p>

<p>What I'd like to do is make tool a constant within the method. Is this possible? </p>