PDA

View Full Version : Class extending , function not defined?



extjs@araneum.nl
19 Jan 2012, 3:55 AM
I'm trying to create an abstract application class with Ext Core (http://www.sencha.com/products/extcore/)

I have a singleton application wich extends the abstract application class.

This is my code :



Ext.namespace('MyCompany');
Ext.namespace('MyCompany.Abstract');
Ext.namespace('MyCompany.Abstract.Application');

Ext.namespace('MyCompany.Application');


MyCompany.Abstract.Application = Ext.extend(Object, {

init: function() {
console.log("MyCompany.Abstract.Application init function");
},

constructor: function() {

console.log("MyCompany.Abstract.Application constructor");

// this fails
MyCompany.Abstract.Application.init.call(this);

// and this also
this.init();
}

});

MyCompany.Application = Ext.extend(MyCompany.Abstract.Application, {

init : function() {
console.log("MyCompany.Application init");
}

})();


When I run the code , I get an error in FireBug



MyCompany.Abstract.Application.init is undefined
MyCompany.Abstract.Application.init.call(this);


Can somebody explain what am I doing wrong?

mitchellsimoens
19 Jan 2012, 8:41 AM
Is this for Ext JS 3 or 4? Ext.extend should not be used in Ext JS 4.

MyCompany.Abstract.Application is a class definition not an instance. If you want to call the init method on a class definition you have to do it on the prototype:


MyCompany.Abstract.Application.prototype.init.call(this);

extjs@araneum.nl
19 Jan 2012, 9:13 AM
Hi ..

It's not reallt ExtJS4 .. I think .. but it's Ext Core .. I coudn't find any forum categories about Ext Core except here.

But I already solved it ..

This seems to work :



/*
Required config such as base namespaces
*/
Ext.namespace('FrameworkCore');
Ext.namespace('FrameworkCore.Abstract');

/*
Abstract class
*/
Ext.namespace('FrameworkCore.Abstract.Application');

FrameworkCore.Abstract.Application = Ext.extend(Object, {

args : null,

// mostly dummy
initialize: function() { },

constructor: function(args) {
this.args = args;
this.initialize();
}

});


Ext.namespace('MyCompany.Application');

var _app = Ext.extend(FrameworkCore.Abstract.Application, {

initialize : function() {
console.log("MyCompany.Application initialize");

console.log(this.args);
}

});


Ext.onReady(function() {
MyCompany.Application = new _app({
test : "test"
});
});