PDA

View Full Version : Get classname and namespace of "this"



Nic
26 Aug 2009, 1:39 PM
Hello,

i was wondering if there is a way to get the component classname of an objects context. For example, if I extend a Panel lets say I create



my.name.space.MyPanel = Ext.extend(Ext.Panel, {
initComponent: function() {
// and here i want to know that "this" is a my.name.space.MyPanel
}
});


is that possible, somehow?

Thanks,
Nic

steffenk
26 Aug 2009, 1:42 PM
why?

Nic
26 Aug 2009, 1:53 PM
Thats a little hard to explain I think. Think of a bunch of classes that all extend a single base class. All the classes should have a method that does something depending on, and only on, the namespace the current object is in. Sure I could implement that method in every class, but thats not the point. And to manually code the namespace or classname in every class is not what I want to do, if the other thing would be possible somehow.

Prototype for example has the klaas property...I'm looking for something like that in ext...

Thanks,
Nic

steffenk
26 Aug 2009, 2:29 PM
you mean something like this?
http://webreflection.blogspot.com/2007/01/javascript-getclass-and-isa-functions.html

Jack9
26 Aug 2009, 3:29 PM
I wish there was reflection! I dont think there's even a standard way to implement it, so I revert to my early practices. I make do with labels and custom vars. See my cleverly named "type" attribute, which is public by default.

if(tab.type == "gridPanel"){}


var tab = new Ext.grid.GridPanel({
title:'tabGridPanel1'
,type:'gridPanel'
,layout:'fit'
,store: [['0','']] // dummy
,columns: [
{
id: 'id'
,header:'ID'
,tooltip: 'ID'
,dataIndex: 'id'
,width: 50
,align: 'center'
}
,{
header: "Name"
,dataIndex: 'name'
,width: 130
}
]
,tbar: new Ext.Toolbar({
height: 25
})
,layoutConfig:{
animate:true
}
});