Results 1 to 3 of 3

Thread: Cannot call parent method with callParent?

  1. #1
    Sencha User
    Join Date
    Oct 2009
    Location
    Portland OR
    Posts
    10

    Default Cannot call parent method with callParent?

    Hi,
    I am having a problem with the following code:

    Code:
    my.Window = Ext.define(null, {
      'extend': 'Ext.window.Window',
      'cls': 'bb-window',
      'bodyCls': 'bb-window-body',
      'border': false,
      'initComponent': function () {
        this.callParent(arguments);
        this.setupListeners();
      }
    });
    
    
    my.Window.prototype.setupListeners = function () {
      // do stuff
    };
    
    
    
    
    my.FormWindow = Ext.define(null, {
      'extend': my.Window,
      'closeAction': 'destroy',
      'modal': true,
      'resizable': false,
      'layout': 'anchor',
      'initComponent': function () {
        this.callParent(arguments);
      }
    }));
    
    
    my.FormWindow.prototype.setupListeners = function() {
      this.callParent(arguments);
      // do something
    };
    In FormWindow I am trying to just add a couple listeners on top of the base class' listeners defined in the setupListeners method. I want something like this:

    new my.FormWindow > my.FormWindow.initComponent > my.Window.initComponent > my.FormWindow.setupListeners > my.Window.setupListeners

    But the last step is never called. Any thoughts?


    Thanks!

  2. #2
    Sencha Premium Member
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585

    Default

    You're fighting the framework using those raw JS techniques. The framework needs to track your classes so that callParent can work:

    Code:
    Ext.define('my.Window', {
      extend: 'Ext.window.Window',
    
      cls: 'bb-window',
      bodyCls: 'bb-window-body',
      border: false,
    
      initComponent: function () {
        // No need to pass arguments, initComponent doesn't have any
        this.callParent();
        this.setupListeners();
      },
    
      setupListeners: function() {
        // do stuff
      }
    });
    
    Ext.define('my.FormWindow', {
      extend: 'my.Window',
    
      closeAction: 'destroy',
      modal: true,
      resizable: false,
      layout: 'anchor',
    
      setupListeners: function() {
        this.callParent();
        // do something
      }
    });

  3. #3
    Sencha User
    Join Date
    Oct 2009
    Location
    Portland OR
    Posts
    10

    Default

    Thanks skirtle,
    Yeah, we are working against the framework a little here but need to in order to leverage some advanced options using the closure compiler. I was able to look at your example and get it working... almost. For some reason the my.FormWindow setupListeners method needs to be in the config obj and can't be prototyped out. Another odd thing was that my.Window needs to have it prototyped out or the compiler can't find it.

    Code:
    my.Window = Ext.define(null, {
      'extend': 'Ext.window.Window',
      'cls': 'bb-window',
      'bodyCls': 'bb-window-body',
      'border': false,
      'initComponent': function () {
        this.callParent();
        this.setupListeners();
      }
    });
    
    
    my.Window.prototype.setupListeners = function () {
      // do stuff
    };
    
    
    
    
    my.FormWindow = Ext.define(null, {
      'extend': my.Window,
      'closeAction': 'destroy',
      'modal': true,
      'resizable': false,
      'layout': 'anchor',
      'initComponent': function () {
        this.callParent();
        // do something
      },
      'setupListeners': function() {
        this.callParent();
        // do something
      }
    }));
    Unfortunately I think the issue is with the compiler.

Posting Permissions

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