title: How to invoke a closure within a function when counting number of times function is invoked
body: <p>I want to count the number of times a function is called on click.  I have this so far but its not quite working.  Can anyone help with this?</p>
  
  <pre><code>function test(){
      var count = (function({
          var i = 0;
          return function(){
             return i += 1;
          }
       })();
  
     if(count() == 2){
       // do this
     }
  
  }
  </code></pre>
  
  <p>Invoke the function like so:</p>
  
  <pre><code>&lt;select onclick="javascript: test();"&gt;
  </code></pre>
  
  <p>It looks like the count function isn't being invoked properly.  How can I invoke the function and perform an operation on it?  I want to perform logic at certain numbers of clicks.  </p>