How to implement a function that fires when a JavaScript object collects garbage?

In fact, garbage was collected, disposed of, or otherwise went out of scope. What I want to do is to cancel the event handlers on elements other than dom when the object that called the bind method is destroyed.


EDIT: I looked at my code once more and decided that the only place I really need is when the module containing this object is no longer needed. This usually happens when the user loads a new view (like "go to a new page", but in AJAX, right?). So, what I did was write a simple wrapper method around the bind method, which modifies the callback function to optionally cancel the handler in the user’s change change event. Then I guarantee that the “view changes” actually starts whenever the view changes.

+3
source share
1 answer

. , - . unbind , .

+3

All Articles