View Full Version : Quick/Preferred way to check object is instance of class, including super classes?

13 Mar 2012, 12:26 PM
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:
var isModel = Ext.isInstance(obj, 'Ext.data.Model')

13 Mar 2012, 12:39 PM
var isModel = obj instanceof Ext.data.Model;

13 Mar 2012, 1:53 PM
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!