View Full Version : [Q] Casting ExtJS objects

29 Mar 2011, 2:32 PM

I am relatively new to ExtJS 3.2.1 and trying to learn it these days.

One problem I currently have is casting ExtJS objects. In my JS code (event handler), I have an object that is being referred as "this" and I was trying to cast it to one of my ExtJS classes. I tried a couple of different things, but none of them worked.

When I did "this instanceof ACT.UserLoginWindow" in FireFox, I got "true". But, when I tried to type-cast this to "ACT.UserLoginWindow", it seemed to failed. Since I am from Java, I tried "((ACT.UserLoginWindow) this).destory();", but it did not work. Also, I tried "var loginWindow = ACT.UserLoginWindow(this)", but it did not work, either. I got "Uncaught TypeError: Object #<Object> has no method 'addEvents'".

Could anyone explain how I can type-cast this to ACT.UserLoginWindow so that I can use the methods on the ACT.UserLoginWindow class? For example, I want to call the "destory()" method on it.

Any help would be highly appreciated.


29 Mar 2011, 11:22 PM
If your instanceof returns true and you are pretty sure the method you want to call exists on the object, just call the method

if(object instanceof sometype)

dont do things like, I would be amazed if that works:

((ACT.UserLoginWindow) this).destory();

javascript isn't java or C#. Just call the method without casting...