title: Using Inheritance Patterns to Organize Large jQuery Applications - how to extend the plugin?
body: <p>I found <a href="https://alexsexton.com/blog/2010/02/using-inheritance-patterns-to-organize-large-jquery-applications/" rel="nofollow">this working example</a> of Inheritance Patterns that separates business logic and framework code. I'm tempted to use it as a boilerplate, but since it is an inheritance Pattern, then how can I <strong>extend</strong> the business logic (the methods in <code>var Speaker</code>)? </p>
  
  <p>For instance, how can I extend a <code>walk:</code> method into it?</p>
  
  <pre><code>/**
   * Object Speaker
   * An object representing a person who speaks.
   */
  var Speaker = {
      init: function(options, elem) {
          // Mix in the passed in options with the default options
          this.options = $.extend({},this.options,options);
  
          // Save the element reference, both as a jQuery
          // reference and a normal reference
          this.elem  = elem;
          this.$elem = $(elem);
  
          // Build the dom initial structure
          this._build();
  
          // return this so we can chain/use the bridge with less code.
          return this;
      },
      options: {
          name: "No name"
      },
      _build: function(){
          this.$elem.html('&lt;h1&gt;'+this.options.name+'&lt;/h1&gt;');
      },
      speak: function(msg){
          // You have direct access to the associated and cached jQuery element
          this.$elem.append('&lt;p&gt;'+msg+'&lt;/p&gt;');
      }
  };
  
  
  // Make sure Object.create is available in the browser (for our prototypal inheritance)
  // Courtesy of Papa Crockford
  // Note this is not entirely equal to native Object.create, but compatible with our use-case
  if (typeof Object.create !== 'function') {
      Object.create = function (o) {
          function F() {} // optionally move this outside the declaration and into a closure if you need more speed.
          F.prototype = o;
          return new F();
      };
  }
  
  $.plugin = function(name, object) {
      $.fn[name] = function(options) {
          // optionally, you could test if options was a string
          // and use it to call a method name on the plugin instance.
          return this.each(function() {
              if ( ! $.data(this, name) ) {
                  $.data(this, name, Object.create(object).init(options, this));
              }
          });
      };
  };
  
  // With the Speaker object, we could essentially do this:
  $.plugin('speaker', Speaker);
  </code></pre>
  
  <p>Any ideas?</p>