13 Mar 2012 12:26 PM #1
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')
var isModel = obj instanceof Ext.data.Model;
13 Mar 2012 12:39 PM #2
- Join Date
- Mar 2007
- Gainesville, FL
- Vote Rating
var isModel = obj instanceof Ext.data.Model;Mitchell Simoens @LikelyMitch
Sencha Inc, Senior Software Engineer
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
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 firstname.lastname@example.org
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is 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!