title: Static variables a jQuery Plugins; how to create?
body: <p>What is the best way to create a static variables for jQuery plugins? </p>
  
  <p>I have 2 example use cases to illustrate my thinking so far; each with some ideas.<br>
  Any other ideas welcomed of course...</p>
  
  <p>One example is for a static variable containing: animation settings, layout settings, product details, etc; the other for a static variable caching data.</p>
  
  <p><em>I hope 'static' is the correct terminolgy here... single globals. please correct if wrong.</em></p>
  
  <p><strong>Case 1: for settings</strong>    </p>
  
  <pre><code>// defining globally
  var anObject = {
   value1 = 0;
   value2 = 0;
  }
  
  jQuery.anObjectSet(partialObject) {
   anObject = jQuery.extend(anObject, partialObject);
  }
  
  jQuery.fn.myPlugin = function (partialObject) {
   obj = jQuery.extend(anObject, partialObject);
  }
  </code></pre>
  
  <p>or maybe?</p>
  
  <pre><code>// adding to the jQuery object
  jQuery.anObject = {
   value1 = 0;
   value2 = 0;
  }
  
  jQuery.anObjectSet(partialObject) {
   jQuery.anObject = jQuery.extend(jQuery.anObject, partialObject);
  }
  
  jQuery.fn.myPlugin = function (partialObject) {
   obj = jQuery.extend(jQuery.anObject, partialObject);
  }
  </code></pre>
  
  <p>or maybe?</p>
  
  <pre><code>jQuery.anObjectSet(partialObject) {
   if(!jQuery.anObject) 
    jQuery.anObject = {
      value1 = 0;
      value2 = 0;
    }
  
   jQuery.anObject = jQuery.extend(jQuery.anObject, partialObject);
  }
  
  jQuery.fn.myPlugin = function (partialObject) {
   if(!jQuery.anObject) 
    jQuery.anObject = {
      value1 = 0;
      value2 = 0;
    }
   obj = jQuery.extend(jQuery.anObject, partialObject);
  }
  </code></pre>
  
  <p><strong>Case 2: for caching</strong> </p>
  
  <pre><code>jQuery.fn.myPlugin = function (newObject) {
   if(!cache[newObject])
    cache[newObject] = $(newObject);
  
   return cache[newObject];
  }
  </code></pre>
  
  <p>or maybe? (I seen this method elsewhere)</p>
  
  <pre><code>window.$cache = {};
  
  jQuery.fn.myPlugin = function (newObject) {
   if(!$cache[newObject])
    $cache[newObject] = $(newObject);
  
   return $cache[newObject];
  }
  </code></pre>
  
  <p>Thanks. I want to build up a .js library, getting starting on the right track...</p>