最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - MooTools: destroy() and events - Stack Overflow

programmeradmin2浏览0评论

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.)

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.)

Share Improve this question asked Jan 30, 2010 at 12:13 JamesBrownIsDeadJamesBrownIsDead 8211 gold badge7 silver badges7 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

.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/

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()).

发布评论

评论列表(0)

  1. 暂无评论