title: Design Patterns used in the jQuery library
body: <p>jQuery is highly focused on the DOM and provides a nice abstraction around it. In doing so, it makes use of various well known <a href="http://en.wikipedia.org/wiki/Design_pattern_(computer_science)" rel="noreferrer">design patterns</a> which just hit me yesterday. One obvious example would be the <a href="http://en.wikipedia.org/wiki/Decorator_pattern" rel="noreferrer">Decorator</a> pattern. The jQuery object provides new and additional functionality around a regular DOM object. </p>
  
  <p>For example, the DOM has a native <a href="https://developer.mozilla.org/en/insertbefore" rel="noreferrer">insertBefore</a> method but there is no corresponding insertAfter method. There are various implementations <a href="http://www.google.com/search?sourceid=chrome&amp;ie=UTF-8&amp;q=dom+insertafter" rel="noreferrer">available</a> to fill this gap, and jQuery is one such library that provides this functionality:</p>
  
  <pre><code>$(selector).after(..)
  $(selector).insertAfter(..)
  </code></pre>
  
  <p>There are many other examples of the Decorator pattern being heavily used in jQuery.</p>
  
  <p>What other examples, big or small, of design patterns have you noticed that are part of the library itself? Also, please provide an example of the usage of the pattern.</p>
  
  <p>Making this a community wiki as I believe that various things people love about jQuery can be traced back to well known design patterns, just that they are not commonly referred to by the pattern's name. There is no one answer to this question, but cataloging these patterns will provide a useful insight into the library itself.</p>