-
13 Mar 2012 12:26 PM #1
Answered: Quick/Preferred way to check object is instance of class, including super classes?
Answered: Quick/Preferred way to check object is instance of class, including super classes?
Is there any way for me to check that an object extends a certain class? I looked through docs and these forums, but couldn't find an answer (even though it seems like it might be a common question).
My use case is this:
I have a method that supports passing in either an instance of a Model (aka a Record), or an HTMLElement. Most of the method can work with either object, but I need to do one special thing if you gave me a record. Since my Model classes extend Ext.data.Model (obviously), I can't check the class name. So what's the best way to determine if the object is a model or not?
My preferred method would be:Code:var isModel = Ext.isInstance(obj, 'Ext.data.Model')
-
Best Answer Posted by mitchellsimoensCode:
var isModel = obj instanceof Ext.data.Model;
-
13 Mar 2012 12:39 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
- Answers
- 3113
Code:var isModel = obj instanceof Ext.data.Model;
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
13 Mar 2012 1:53 PM #3
Thanks for another answer to an extremely easy question. For some reason I wasn't thinking about these as being part of a true class hierarchy. Thanks!


Reply With Quote