Skip to content

Instantly share code, notes, and snippets.

@vanm
Created June 16, 2011 16:36
Show Gist options
  • Select an option

  • Save vanm/1029643 to your computer and use it in GitHub Desktop.

Select an option

Save vanm/1029643 to your computer and use it in GitHub Desktop.
Remove Associated Elements
// Instantiate a Component
var newComponent = new Component({
// Init creates domElement and associatedElements properties
// Override removeElement method
removeElement: function(){
this.domElement.remove();
$.each(this.associatedElements, function(){
$(this).remove();
});
this.domElement = null;
this.associatedElements = [];
}
});
// Later in the application lifecycle you create a flashContainer
// and want to ensure it's cleaned up alongside the newComponent.domElement
newComponent.associatedElements.push(flashContainer);
// removeElement destroys the domElement and flashContainer.
newComponent.removeElement();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment