javascript 从 jquery 对象中删除函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17231596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 07:33:57  来源:igfitidea点击:

Remove function from a jquery object

javascriptjquery

提问by Lim H.

How can I remove a function from a jquery object? For example, I have

如何从 jquery 对象中删除函数?例如,我有

$('#element').func = function() {
     // function body goes here
}

And later on I want to remove funcfrom $('#element'). I've tried deletebut it doesn't work. Thanks.

后来我想func$('#element'). 我试过了,delete但它不起作用。谢谢。

回答by Marvin Emil Brach

How about this?

这个怎么样?

$('#element').fn.func = null;

or

或者

$('#element').prototype.func = null;

or

或者

delete $('#element').fn.func;

or

或者

delete $('#element').prototype.func;

For understanding what the prototype is, have a look here: How does JavaScript .prototype work?

要了解原型是什么,请看这里:JavaScript .prototype 是如何工作的?

回答by Suresh Atta

you can do by assigning null.

您可以通过分配 null 来完成。

$('#element').fn.func = null;