title: Passing Parameters into a Callback Function
body: <p>I have a function that listens for a click on the screen and fires a callback. It is part of a Helper object (which is why is preceded by the term Helper in my sample code. That is irrelevant however.</p>
  
  <pre><code>var Helper = { 
      bodyClickListener: function(fn) {
          var window = document.getElementsByTagName('body')[0];
          window.click();
          CORE.dom.on(window, 'click', function(event) {
              CORE.dom.off(window, 'click');
              fn(event);
          });
      }
  }
  </code></pre>
  
  <p>I need to be able to pass a function into this function with a parameter that has been previously set.</p>
  
  <pre><code>function someFunction() {    
      var popup = document.getElementById('tagResultsPopup');
      Helper.bodyClickListener(function(popup) {
          return function(event) {
              event.stopPropagation();
              removePopup(popup);
          };              
      }(document.getElementById('tagResultsPopup')));
  
      function removePopup(element) {
          if(element) {
              element.parentNode.removeChild(element);
          }
      };
  }
  </code></pre>
  
  <p>The code above works, but you'll notice that I have to set the popup variable inside of the callback function. It has already been set above. How do I pass a  reference to the earlier variable into the callback function.</p>