Is there an elegant way to overload a jQuery method inside of a plugin only?
<p>I am having a bit of a <em>dull</em> moment today, where I can't think of an elegant solution for this problem.</p>

<p>I have inherited a plugin, and I need to modify it to allow passing a <em>enabled</em> or <em>disabled</em> state to it, to have it detach all of its events, show the <em>disabled</em> state, etc.</p>

<p>Like a jQuery UI <em>plugin</em>, I was simply going to use...</p>

<pre><code>$('div').myPlugin('disabled');
</code></pre>

<p>This I have no problem with.</p>

<p>However, the plugin attaches many events which are not <a href="http://docs.jquery.com/Namespaced_Events" rel="nofollow">namespaced</a>. I want the events to be namespaced, so I can remove the events easily.</p>

<p>There are many events that are bound, so I thought <em>hey, why don't I overload <a href="http://api.jquery.com/bind/" rel="nofollow"><code>bind()</code></a> to attach the namespace automatically?</em></p>

<p>I came up with this...</p>

<pre><code>(function(oldBind) {
    $.fn.bind = function() {
        if (arguments.length &gt;= 2) {
            arguments[0] += '.my-plugin';
        }
        return oldBind.apply(this, arguments);
    }
})($.fn.bind);  
</code></pre>

<p>I placed this at the top of the plugin, before the <code>return this.each(fn)</code> code.</p>

<p>It seemed to work nicely.</p>

<p>However, I tossed in a <code>console.log(arguments[1].toString())</code> and noticed (as I expected) this overwrote the main jQuery <code>bind()</code> outside of the plugin.</p>

<p>What is the best way to have this overloaded <code>bind()</code> only available to this plugin?</p>

<p>Should I simply place at end of the plugin <code>$.fn.bind = oldBind</code> or is there an easier way? </p>
