title: JavaScript - Passing Arguments to Anonymous Functions
body: <p>I'm calling an anonymous function:</p>
  
  <pre><code>        closeSidebar(function() {
              alert("function called");
              $(this).addClass("current");
              setTimeout(function(){openSidebar()}, 300);
          });
  </code></pre>
  
  <p>But <code>$(this)</code> doesn't work as expected and I need to pass it as an argument into the function. After a bit of research I thought this would work:</p>
  
  <pre><code>            closeSidebar(function(el) {
                 $(el).addClass("current");
                 setTimeout(function(){openSidebar()}, 300);
              })(this);
  </code></pre>
  
  <p>But it doesn't. How do I add arguments to an anonymous function?</p>
  
  <p><a href="http://jsfiddle.net/H7Mxs/13/" rel="nofollow">jsFiddle</a> - Click a button on the right, it animates in then calls the function above. When the button has the class "current" it will have a white bar on the left side of the button but the class never changes.</p>