title: jQuery plugin 'this.each is not a function'
body: <p>I am trying to create my first jQuery plugin and I am geting the error <code>this.each is not a function</code>, which is referencing this line <code>return this.each(function() {</code> in the <code>bindUi</code> method. I thought that <code>this</code> referred to the "jQuery object the plugin was invoked on", which in my case would be the <code>#location</code> node I used when creating my plugin with <code>$('#location').locationSearch()</code>, right? I get this error on page load.</p>
  
  <p>Here is my plugin code:</p>
  
  <pre><code>(function($) {  
    var methods = {
      init : function( options ) {
  
        return this.each(function() {
  
          var settings = {
            //none yet
          };
  
          if ( options ) { 
            $.extend( settings, options );
          }        
          methods.log('init');
  
          //attach events
          methods.bindUi();        
        });
  
      },
  
      destroy : function( ) {
         return this.each(function(){ });
      },
  
      bindUi : function() {
  
        return this.each(function() {
  
          methods.log('bindUi');
          this.click(function() {
            methods.log('clicked');
          });
  
        });
  
      },    
  
      log : function(text) {
        if (window.console &amp;&amp; window.console.log) {
          window.console.log(text);
        };
      }
  } // end methods
  
    jQuery.fn.locationSearch = function(method) { 
      if ( methods[method] ) {
        return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
      } else if ( typeof method === 'object' || ! method ) {
        return methods.init.apply( this, arguments );
      } else {
        $.error( 'Method ' +  method + ' does not exist on jQuery.tooltip' );
      }    
    };
  })( jQuery );
  </code></pre>
  
  <p>I am also a little confused if every one of my methods needs to use <code>return this.each(function() { ..</code> or if only the init and destroy methods use it?</p>