title: How to access the sub method inside a method from a jquery plugin?
body: <p>How can I access the sub method inside a method from a plugin? For instance, in the <code>init</code> method, I want to access the <code>page</code> method inside <code>manage</code>,</p>
  
  <pre><code>$this.cms(manage.page); // ReferenceError: manage is not defined
  </code></pre>
  
  <p>the basic structure,</p>
  
  <pre><code>(function($){
  
      var methods = {
  
          defaults: function(options) {
  
              // Default options.
              var defaults = {
                  setup: {
                      directory: ""
                  }           
              }
  
              // Always leave this line here.
              var options = $.extend(defaults, options);
  
              // Return the processed options.
              return options;
  
          },
  
          init : function( options ) {
  
              // Must declare a this as the plugin's root itself.
              var $this = this;
  
              // Call the local method from the plugin itself to get the processed options.
              var o = $this.cms('defaults',options);
              //alert("nothing to load");
  
  
              $this.cms(manage.page);
          },
  
          manage : {
  
              page: function(options){
  
                  // Must declare a this as the plugin's root itself.
                  var $this = this;
  
                  // Call the local method from the plugin itself to get the processed options.
                  var o = $this.cms('defaults',options);
  
                  alert("page method");
  
              },
              menu: function(options){
              }
  
          },
  
          add : function( options ) {
  
          },
  
          erase : function( options ) { 
  
          },
  
          remove: function(object,options) { // to be developed.
  
          }
      };
  
      $.fn.cms = function( method ) {
  
          // @reference: http://docs.jquery.com/Plugins/Authoring#Namespacing
          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 );  // always change 'init' to something else if you different method name.
          } else {
              $.error( 'Method ' +  method + ' does not exist on jQuery.cms' );
          }
  
          return this; // this is needed to ensure chainability @reference: http://stackoverflow.com/questions/14008121/jquery-namespace-how-to-pass-default-options-from-one-method-to-the-subsequence
  
      };
  
  })(jQuery);
  </code></pre>
  
  <p>Is it possible or any other better way of doing it? I just want to have children methods inside the parent methods.</p>