简体   繁体   English

如何完全删除jQuery.prototype插件?

[英]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,到处绑定事件,就无法删除它并使用一些神奇的命令进行清理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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