PDA

View Full Version : Cannot call parent method with callParent?



GangleTron
27 May 2014, 9:08 AM
Hi,
I am having a problem with the following 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!

skirtle
27 May 2014, 7:42 PM
You're fighting the framework using those raw JS techniques. The framework needs to track your classes so that callParent can work:


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

GangleTron
28 May 2014, 11:32 AM
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.


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.