Sorry for my english, I'm french :) I created a Mootools class named "Slider". This class has a "slider_element" attribute, which is a DIV element. The class also has a "destroyer" method. This method destroys the DIV element.
The slider_element is supposed to be a div that contains another DIV with a "remove" CSS classname. When I click on the "remove DIV", I want the "destroyer" method to be called, so that the DIV disappears.
Here is my code below, and it works graphically like I want. My question is : when I destroy the DIV element, I don't need no more my Slider instance (here "mySlider"). But my code destroys the DIV elements, not the slider instance. Do this instance still exist ? I suppose yes. So I searched how to destroy an instance of a class with Mootools, but didn't find ... so I supposed I'm doing something the wrong way, even if my code does what I want graphically. Please help :)
var Slider = new Class({
initialize: function(slider_element){
this.slider_element = slider_element;
this.slider_element.getElements('*[class="remove"]').addEvent('click', this.destroyer.bind(this));
},
destroyer: function(){
this.slider_element.destroy();
}
});
var myElement = $('my_slider');
var mySlider = new Slider(myElement);
(in reality, this is a simplified code, so that I don't disturb you with my whole code)
mySlider.method()
i'd say, don't save it as a var. justnew Slider(document.id("my_slider"));
but the instance will live on, even if its DOM functionality is removed. also,this.slider_element.getElements(".remove")
is better butthis.slider_element.addEvent("click:relay(.remove)", this.destroyer.bind(this))
will be using less memory and smaller footprint (through element delegation). - Dimitar Christoff