jQuery plugin: plugin methods calling other plugin methods?
<p>I have a plugin definedlike so:</p>

<pre><code>(function( $ ){
    var mymethods = {
        init: function(opts) {
            // do some wild awesome magic
            if (opts.drawtablefirst) $(this).drawtable(); // This doesn't actually work of course
        },

        drawtable: function() {
            $(this).empty().append($("&lt;table&gt;")); // Empty table, I know...
        }
    }

    // Trackman table
    $.fn.myplugin = function(method) {

        if (mymethods[method] ) {
            return mymethods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method ) {
            return mymethods.init.apply(this, arguments);
        }
    }
})( jQuery );
</code></pre>

<p>I want to be able to call the <code>drawtable</code> method from the <code>init</code> method, but that approach isn't working. I instantiate my plugin mostly like:</p>

<pre><code>$("div#container").myplugin({drawtablefirst: true})
</code></pre>

<p>But sometimes I don't want to pass <code>drawtablefirst</code> and then later call it manually, like:</p>

<pre><code>$("div#container").myplugin('drawtable')
</code></pre>

<p>What is the best way to configure this so <code>drawtable</code> is an accessible plugin method, but also can be called from within the plugin methods themselves such as <code>init</code>?</p>

<p>Also, accessing the original element in <code>drawtable</code> via <code>$(this)</code> doesn't seem to work. What's the proper approach there?</p>

<p>Thanks.</p>
