简体   繁体   中英

How to completely remove a jQuery.prototype plugin?

Let's say I have a plugin, for example:

(function (jQuery) {
    var somevars = 0;

    jQuery.fn.someFunc = function () {
      // do some work
    };

    jQuery.fn.myPlugin = function (options) {
      // do some initialization etc...
    }
})(jQuery);

jQuery(document).ready(function () {
    jQuery(".someclass").myPlugin();
});

Now let's say I want to remove it completely with something like:

jQuery(".someclass").destroy("myPlugin");

How can I do that? Completely remove the plugin from the object , functions, data, events, everything.

UPDATE

Assume no method to destroy itself exist, assume you are using someone else plugin which self bind to few elements on the page when initialized, and assume after some interaction with the user you need to completely remove it with all its binding.

Is it possible? Or the only solution is to go through the code of the plugin and discover how to remove it and add some methods to remove it?

给定一个插件可以做多少事情,更改DOM,到处绑定事件,就无法删除它并使用一些神奇的命令进行清理。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM