title: Make the new keyword optional
body: <p>Say I want to create the following API:</p>
  
  <pre><code>var api = function(){}
  
  api.prototype = {
    constructor: api,
    method: function() {
      return this;
    }
  };
  </code></pre>
  
  <p>Now, this will work like:</p>
  
  <pre><code>var myApi = new api();
  myApi.method();
  </code></pre>
  
  <p>But let’s say I want to make the <code>new</code> keyword optional, so that this will work:</p>
  
  <pre><code>api().method();
  </code></pre>
  
  <p>I would out of my head do:</p>
  
  <pre><code>var api = function() {
    if ( !(this instanceof api) ) {
      return new api();
    }
  };
  </code></pre>
  
  <p>But I was wondering, could this easily be infected somehow, or are there other dangers around using this method? I know that f.ex jQuery don’t do this (they offload the constructor to a prototype method), so I’m sure there are good reason for not doing this. I just don’t know them.</p>