JamesBrownIsDead
JamesBrownIsDead

Reputation: 821

MooTools: destroy() and events

When I .destroy() an Element object in MooTools, does .destroy() automatically internally call element.removeEvents(), or do I need to keep this in mind. (I'm removing elements from the DOM that have previously had element.addEvent() called.)

Upvotes: 3

Views: 4487

Answers (2)

Nick Craver
Nick Craver

Reputation: 630559

.destroy() in MooTools, version 1.2.4:

destroy: function(){
    Element.empty(this);
    Element.dispose(this);
    clean(this, true);
    return null;
}

The clean(item, retain) function does .removeEvents() if the browser needs it:

var clean = function(item, retain){
    ....
    if (item.clearAttributes){
        var clone = retain && item.cloneNode(false);
        item.clearAttributes();
        if (clone) item.mergeAttributes(clone);
    } else if (item.removeEvents){          
    ....
};

You should be safe, it's emptying out the elements.

Also, credit for all code above to MooTools of course: http://mootools.net/

Upvotes: 3

Håvard S
Håvard S

Reputation: 23886

Yes, Mootools will call removeEvents() when you call destroy() on an element.

(The current implementation does this in a function called clean() that is called from destroy()).

Upvotes: 2

Related Questions