javascript - Remove extended function - Stack Overflow

admin2025-04-22  0

How to get rid of extended $.extend() function from a specific target object. Example: By reloading parts of the DOM with XHR, I'm able to detect the appearance of the object like this:

// Initliaize:
$('#sausage').catsup();
    ...
// Inside fn.catsup():
if($('body').find($(this)).size() == 0) // object has gone

But how can I kill fn.catsup()? This seems not to work:

$(this).clearQueue();
$(this).stop();
$(this).unbind();
delete $(this);

How to get rid of extended $.extend() function from a specific target object. Example: By reloading parts of the DOM with XHR, I'm able to detect the appearance of the object like this:

// Initliaize:
$('#sausage').catsup();
    ...
// Inside fn.catsup():
if($('body').find($(this)).size() == 0) // object has gone

But how can I kill fn.catsup()? This seems not to work:

$(this).clearQueue();
$(this).stop();
$(this).unbind();
delete $(this);
Share Improve this question edited Mar 28, 2012 at 10:56 gdoron 150k59 gold badges302 silver badges371 bronze badges asked Mar 28, 2012 at 10:33 mate64mate64 10.1k17 gold badges66 silver badges98 bronze badges 3
  • 2 What do you mean by 'kill catsup()'? – Flash Commented Mar 28, 2012 at 10:36
  • 1 @msec. Now I'm even more confused, what are you trying to do? Can you give us the context? it's very hard to understand the question. – gdoron Commented Mar 28, 2012 at 10:42
  • If you want a way to "destroy" the actions done by catsup you will have to write another function (even better add a method to catsup itself) that will do so. – m90 Commented Mar 28, 2012 at 10:49
Add a ment  | 

2 Answers 2

Reset to default 7

If I understood the question, you want to remove your function from jQuery.

use this:

$.fn.catsup = null;

Or as suggested by @Matt:

delete $.fn.catsup

Unless I understood it wrongly, you simply want catsup to not be part of jQuery extension functions anymore:

delete $.fn.catsup;

Note that this will not affect all jQuery DOM objects, i.e. both existing ones and those created afterwards.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745284671a294316.html

最新回复(0)