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
Remove function from a jquery object
提问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 func
from $('#element')
. I've tried delete
but 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;