PDA

View Full Version : Problem initializing application with an extended class



marvinhorst
29 Oct 2010, 10:25 AM
I'm redoing some old Extjs code and I'm using extended classes. This is probably a newbie question but.....

Why does this code work?

Ext.onReady(function() {
var viewport = new Ext.Viewport({
layout : 'fit',
items : [
{xtype: 'employeebrowser'}
]
});
viewport.show();
});

but this code gives me an error?

HR = function() {

return {
init : function() {
var viewport = new Ext.Viewport({
layout : 'fit',
items : [
{xtype: 'employeebrowser'}
]
});
viewport.show();
}
};
}();

Ext.onReady(HR.init(), HR);

The error is: HR.EmployeeBrowser is undefined
http://www.pbzinc.loc/hr/public/scripts/EmployeeBrowser.js
Line 21

Here is the code excerpt from the EmployeeBrowser file:
HR.EmployeeBrowser = Ext.extend(Ext.Panel, {
layout: 'border',
border: false,
region: 'center',
initComponent: function () {
this.items = [

this.buildDepartmentDv(), this.buildEmployeeDv()];


HR.EmployeeBrowser.superclass.initComponent.call(this);
},

....other code ..........

});

Ext.reg('employeebrowser', HR.EmployeeBrowser);

marvinhorst
29 Oct 2010, 10:27 AM
Line 21 where the error occurs is


HR.EmployeeBrowser.superclass.initComponent.call(this);

marvinhorst
29 Oct 2010, 10:53 AM
Another correction .....

Ext.onReady(HR.init(), HR);
is actually

Ext.onReady(HR.init, HR);

plalx
29 Oct 2010, 11:41 AM
Are you including the HR script before the EmployeeBrow.. script? Because if you execute the HR script after other scripts, by doing HR = function(){...}(); you overwrite the HR variable...