title: Adding code to an existing function inside loop
body: <p>In an object I have defined some events: the key is the event name and the value is the callback function. Here is an exemple:</p>
  
  <pre><code>vm.events = {
      check_node: function(node, selected){
          ...
      },
      uncheck_node: function(node, selected){
          ...
      }
  };
  </code></pre>
  
  <p>I want to add some code to those functions so I did the following:</p>
  
  <pre class="lang-php prettyprint-override"><code>for (var evt in scope.tree.events) {
      if (scope.tree.events.hasOwnProperty(evt)) {
          var cb = scope.tree.events[evt];
          scope.tree.events[evt] = function(...args){
              cb(...args);
              controller.$setDirty();
              scope.$evalAsync();
          };
          scope.tree.view.on(evt.indexOf('.') &gt; 0 ? evt : evt + '.jstree',  scope.tree.events[evt]);
      }
  </code></pre>
  
  <p>But JSHint logs the following warning:</p>
  
  <pre><code>Functions declared within loops referencing an outer scoped variable may lead to confusing semantics. (W083)
  </code></pre>
  
  <p>How can I solve this ?</p>