Results 1 to 3 of 3

Thread: AbstractComponent - can I override the onDestroy method?

  1. #1
    Sencha Premium User
    Join Date
    Nov 2010
    Vote Rating

    Default AbstractComponent - can I override the onDestroy method?

    Can a subclass override the AbstractComponent.onDestroy method? ... or is this method private and should I override the beforeDestroy method instead?

    Ext.define('Ext.AbstractComponent', {
         * Invoked before the Component is destroyed.
         * @method
         * @template
         * @protected
        beforeDestroy : Ext.emptyFn,
        onDestroy : function() {

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Gainesville, FL
    Vote Rating


    Any subclass can override it but it does a few things that you would need to clean up. I would just do a callParent
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2

    Think my support is good? Get more personalized support via a support subscription.

    Need more help with your app? Hire Sencha Services

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Vote Rating


    Personally I wouldn't hesitate to override onDestroy if I needed to add destruction logic to a custom component. Choosing between onDestroy and beforeDestroy seems to be just a matter of timing.

    Methods with names that sound like events (e.g. onDestroy, afterRender) are to be thought of as 'internal events', intended to be overridden in subclasses. Of course you have to take care to call the overridden method at the appropriate time.

    There are some really old posts that you may find interesting. Here's one from Jack Slocum explaining his use of template methods in ExtJS 1. This principle remains in the current framework:

    Later in the same thread he touches upon why he chose to name some methods after events:

    This blog post from Nige White also touches upon this subject. Most of the post is about writing plugins but if you skim down you'll find he discusses some of the template methods in the framework:

    He also explains some of the reasons why overriding methods is more appropriate than listening to events when writing an extension.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts