title: jQuery prototype and constructor function chaining
body: <p>How would jQuery allow its constructor to act as a function accepting arguments meanwhile its constructor also acts as a function accepting arguments?</p>
  
  <p>I am a bit new to JavaScript, so excuse me if this is a noob question, (I have looked at the source but it's hard to try to dissect).</p>
  
  <p>Anyway, as an example <code>$(document).ready(&lt;args&gt;);</code> Both the constructor <code>$()</code> and the prototype <code>ready()</code> act as a function. How? Because if I try this:</p>
  
  <pre><code>var $ = function( selector ) {
      if(selector == document) {
          return document;
      }
  };
  
  $.prototype = {
      constructor: $,
      ready: function( args ) {
          if( isDomReady ) {
              args.apply( document );
          } else {
              window.onload = args;
          }
      }
  };
  
  var isDomReady = ( document.addEventListener || document.readyState == ("complete"|"loaded"|true|4) || document.onreadystatechange() ) ? true : false;
  
  $(document).ready(function() { alert("Wibbles!") });
  </code></pre>
  
  <p>I get an error <kbd>Uncaught TypeError: Object[object global] has no method 'ready'</kbd> </p>