PDA

View Full Version : Inheritance and graphical objects



Asken
21 Oct 2010, 3:05 AM
Hey guys,

I have a question on inheritance when developing new gui objects.

My base class:


(function() {
var BaseApplication = Ext.extend(Object,{
applicationName:'BaseApplication',
taskPanel:null,
constructor:function(config) {
Ext.apply(this, config);
},
getApplicationName:function() {
return this.applicationName;
},
getTaskPanel:function() {
return this.taskPanel;
}
})

nsUx.BaseApplication = BaseApplication;
})()


Inherited class:

nsUx.TestApplication = function(config) {
nsUx.TestApplication.superclass.constructor.call(this, config);

return new Ext.Viewport({
applicationName:this.applicationName,
init:function() {
// how do I access the base class getApplicationName() prototype function? "this" is no longer TestApplication
// but instead the Viewport
}
});
}

Ext.extend(nsUx.TestApplication, nsUx.BaseApplication,{});


Creating an instance:

var app = new nsUx.TestApplication({applicationName:'test application'});


What is the best way to make the prototype stuff available for the view port? Returning an object will break inheritance.

K

jay@moduscreate.com
21 Oct 2010, 4:53 AM
you should not return a new viewport inside of a constructor. The constructor typically returns the new object it created. Look at the ExtJS patterns used on the web. You'll quickly find how your pattern is flawed.