Method delegation in Javascript/jQuery?
<p>I have this code:</p>

<pre><code>var myWidget = $('#myWidget');
</code></pre>

<p>and calls like this elsewhere:</p>

<pre><code>myWidget.hide();
myWidget.slideToggle();
</code></pre>

<p>These work of course because jQuery adds these methods.</p>

<p>Now, let's say I'm doing some refactoring to make myWidget a proper object with its own custom methods and state:</p>

<pre><code>var myWidget = (function() {
    // private stuff
    var actualJQueryObject = $('#myWidget');
    return {
        publicMethod: function() {...},
        // MAGIC!
    }
})()
</code></pre>

<p>but I want to have all the calls that expect a jQuery object, which are all around my code, to <em>still work even though myWidget is no longer a jQuery object</em>, because myWidget knows how to delegate these calls to actualJQueryObject.</p>

<p>Is this possible?</p>
