title: How can I pass arguments to anonymous functions in JavaScript?
body: <p>I'm trying to figure out how to pass arguments to an anonymous function in JavaScript.</p>
  
  <p>Check out this sample code and I think you will see what I mean:</p>
  
  <pre><code>&lt;input type="button" value="Click me" id="myButton" /&gt;
  
  &lt;script type="text/javascript"&gt;
      var myButton = document.getElementById("myButton");
      var myMessage = "it's working";
      myButton.onclick = function(myMessage) { alert(myMessage); };
  &lt;/script&gt;
  </code></pre>
  
  <p>When clicking the button the message: <code>it's working</code> should appear.  However the <code>myMessage</code> variable inside the anonymous function is null.</p>
  
  <p>jQuery uses a lot of anonymous functions, what is the best way to pass that argument?</p>