title: Use loop to bind events
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>//I hava this tool function to bind event
  var bindEvent = function($dom,events,data,_this){
    for(var key in events){
      $dom.bind(key,function(){
        events[key].apply(_this,[data]);
      });
    }
  };
  
  //and use like this
  var events = {
    click:function(){
      alert("click");
    },
    dblclick:function(){
      alert("dblclick");
    }
  };
  
  var $btn = $("#btn");
  bindEvent($btn,events,"mydata",$btn);</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;button id="btn"&gt;MYBtn&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>when i click on the button, dblclick event is always being triggered.<br>
  I know, the reason of this problem.<br>
  There is a closure when bind event which is used in "for" loop. Upon termination of loop, the last object in memory (there is dbclick callback function).<br>
  so, when trigger <code>click</code> event, it run <code>alert("dblclick")</code>.<br>
  I want to know if had a good way to solve this problem.
  Or have a good way to implement tool function for bind event.<br>
  Thank you very much.</p>