title: How to Extend Twitter Bootstrap Plugin
body: <p>I am digging into Twitter's Bootstrap and now want to try and add some functionality to the plugins, but I can't figure out how to do so.  Using the modal plugin as an example (<a href="http://twitter.github.com/bootstrap/javascript.html#modals">http://twitter.github.com/bootstrap/javascript.html#modals</a>), I'd like to add a new function to the plugin that can be called as one would the standard plugin methods.  THe closest I think I have come is with the following code, but all I get when I try to access is that the function is not part of the object.  </p>
  
  <p>Any suggestions?  This is what I have tried that seems to be the closest to what I need to do:</p>
  
  <pre><code> $.extend($.fn.modal, { 
      showFooterMessage: function (message) { 
          alert("Hey"); 
      } 
  }); 
  </code></pre>
  
  <p>Then I would want to call it as follows:</p>
  
  <pre><code>  $(this).closest(".modal").modal("showFooterMessage"); 
  </code></pre>
  
  <p>EDIT: OK, I figured out how to do this:  </p>
  
  <pre><code>(function ($) {
      var extensionMethods = {
          displayFooterMessage: function ($msg) {
              var args = arguments[0]
              var that = this;
  
              // do stuff here
          }
      }
  
      $.extend(true, $.fn.modal.Constructor.prototype, extensionMethods);
  })(jQuery);
  </code></pre>
  
  <p>The problem with the existing set of Bootstrap plugins is that if anyone wants to extend them, none of the new methods can accept arguments.  My attempt to "fix" this was to add the acceptance of arguments in the plugins function call.</p>
  
  <pre><code>$.fn.modal = function (option) {
      var args = arguments[1] || {};
      return this.each(function () {
          var $this = $(this)
          , data = $this.data('modal')
          , options = typeof option == 'object' &amp;&amp; option
  
          if (!data) $this.data('modal', (data = new Modal(this, options)))
  
          if (typeof option == 'string') data[option](args)
          else data.show()
  
      }) // end each
  } // end $.fn.modal
  </code></pre>