Teardown on plugins

Teardown on plugins

Is there a 'teardown' for plugins that can get triggered automatically
(similar to that for events)?
It's extremely common, and a source of bugs when I see:
$.fn.mySuperPlugin = function(){
...code ...
$(document).click(function(e) { ...code... });
...code...
}
Yes, they should be doing adding/removing this event listener every
time their widget 'comes to life'. But there are cases where even
this doesn't work.
I think I remember John talking about this when we were discussing
"jQuery Enterprise". It was something like:
$.fn.extend("pluginName",{
setup: function( ...),
teardown: function( ...)
})
In JMVC, I've hacked .remove() to enable plugins to write 'teardown'
functionality. For jQuery, when you use the fn.extend function, it
will wrap setup with something that would add teardown to something
like:
$(el).data("plugins")["pluginName"] = teardown.
When remove() is called, it will get all the plugins on the current
element, and call their teardown code.
Someone would also be able to remove a single plugin like:
$(el).data("plugins")["pluginName"]()
Ugly, but the case where you want to remove just one plugin is rare.
Thoughts?
--