2010-01-30 61 views
3

當我在MooTools中使用.destroy()Element對象時,確實如此。 destroy()自動內部呼叫element.removeEvents(),或者我需要記住這一點。 (我除去先前已經有element.addEvent()叫DOM元素。)MooTools:destroy()和事件

回答

2

.destroy()在MooTools的,1.2.4版本:

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

乾淨(項目,保留)功能確實.removeEvents()瀏覽器是否需要它:

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){   
    .... 
}; 

你應該是安全的,它的走光了元素。

此外,信貸的所有代碼上面當然MooTools的:http://mootools.net/

+0

如果瀏覽器支持它,但是如果發送到'clean()'函數的'item'確實如此,則不行。 'removeEvents()'是一個Mootools函數本身,而不是內建函數。 – 2010-01-30 12:29:16

+0

@HåvardS - 實際上我修剪了一些邏輯,它被封裝在一個'if(Browser.Engine.trident){'以及基本上是一個IE檢查...其他瀏覽器已經正確地移除事件,這是一個只有IE的內存泄漏創可貼。我將上面的「支持」改爲「需要」......希望得到更清楚的答案。 – 2010-01-30 12:40:11

2

是,MooTools的會叫removeEvents()當你一個元素上調用destroy()

(當前的實施方式在名爲clean()的函數中執行此操作,該函數從destroy()調用)。