PDA

View Full Version : Publich methods in extended class



DiscoBoy
13 May 2009, 9:03 AM
How can i define a new public function in an extended class?

My example:


Ext.ns('WS', 'WS.ui', 'WS.tb');

WS.Main = Ext.extend(Ext.Panel, {
constructor: function(config) {
Ext.apply(this, {
html: 'My extended panel',
width: 300,
height: 300,
msg: function(message){
alert(message);
}
});
WS.Main.superclass.constructor.apply(this, arguments);
}
});

// Application main entry point
Ext.onReady(function() {
WS.Main.msg("Hello");
});
This is not the real code of my application but just a sample of how i want to achieve the functionality. The error i get is that "WS.Main.msg" is not a funtion. I already tried it with return (which should provide public funtions as i understood).

My intension ist create reusbale UI-components --> WS.ui
and toolboxes which provide common functionality --> WS.tb

I inspiration came from one of SAKI's tutorials where he also uses:



// application main entry point
Ext.onReady(function() {
Ext.QuickTips.init();
// code here
});

Animal
13 May 2009, 10:06 AM
You've created a class. Just read ANY Ext code. Any OO language.

You have to the instantiate that class

The documentation tells you how to use it: http://extjs.com/deploy/ext-3.0-rc1.1/docs/?class=Ext

DiscoBoy
13 May 2009, 10:24 AM
Thx for the reply! I thought so too, but then SAKI's example made me confused and thinking it goes also this way...
So Ext.QuickTips.init(); works only because Ext has alreay been in instantiated?

Animal
13 May 2009, 10:36 AM
Ext.QuickTips is a singleton; an object with methods: http://extjs.com/deploy/ext-3.0-rc1.1/docs/?class=Ext.QuickTips