title: Javascript passing events to a function
body: <p>Why does the first method work but not the second?</p>
  
  <p>I'm stumped why I can pass an event to a function using the first method, but not the second. To me these should work identically. Loosely based off of <a href="https://stackoverflow.com/questions/6486084/obtain-mouse-coordinates-through-chrome-extension" title="obtain mouse coordinates">Obtain Mouse Coordinates</a>.</p>
  
  <p>This does work:</p>
  
  <pre><code>document.onclick = function (e) {
    var x = e.pageX;
    var y = e.pageY;
    console.log(x);
  };
  </code></pre>
  
  <p>This does not work. It returns "Uncaught ReferenceError: z is not defined".</p>
  
  <pre><code>document.onclick = mousePosition(z);
  
  function mousePosition (e) {
    var x = e.pageX;
    var y = e.pageY;
    console.log(x);
  };
  </code></pre>