title: Using a variable as an object and a function
body: <p>I am trying to mock the <code>times</code> function from the JavaScript library <a href="http://underscorejs.org/#times">Underscore.js</a>.</p>
  
  <p>This function accepts two syntaxes :</p>
  
  <pre><code>_.times(3, function(n) {
      console.log("hello " + n);
  });
  </code></pre>
  
  <p>and</p>
  
  <pre><code>_(3).times(function(n) {
      console.log("hello " + n);
  });
  </code></pre>
  
  <p>So far I succeeded to mock the first one by creating an <code>_</code> object like this :</p>
  
  <pre><code>var _ = {
      times: function(reps, iteratee) {
          // a loop
      }
  };
  </code></pre>
  
  <p>And the second syntax by creating an <code>_</code> function which returns an object :</p>
  
  <pre><code>function _(n) {
      return {
          times: function(iteratee) {
              // a loop
          }
      };
  }
  </code></pre>
  
  <p>But I can't use these 2 methods together. I need to find a way that will allow both syntaxes.
  Do you have any idea how I could use the <code>_</code> character as an object as well as a function ?</p>