title: How to avoid the javascript closure in the slide end event
body: <p>I have the following code for jquery ui slider. </p>
  
  <pre><code>var setupChartControllers = function () {
      for (var i = 0; i &lt; 3; i++) {
          $("#chart-range-"+ i).slider({
              orientation: "vertical",
              range: true,
              values: [0, 100],
              stop: function (event, ui) {
                  sliderEndFunc(event, ui, i);
              }
          });
      }
  }
  var sliderEndFunc = function (event, ui, chartNumber) {
      drawChart(chartNumber);
  }
  </code></pre>
  
  <p>The problem is that "i" is a variable in the closure. By the time slide end event triggers we get the value of i=3 for all events. How can I pass a variable as a value instead of variable? (need something like value type versus reference type of oop) I want the chart-range-1 trigger drawChart(1). </p>