How to get type name of YUI object?
- Hello Folks
I noticed that, using toString() method
I can get type name of (any? all?) YUI objects
but is it better, preferred way?
yuiObjTypeName = yuiObj.toString().split(" ");
and it is customary for them to redefine the toString method to identify
themselves, but that is a convention that many components (not YUI) might
not follow and how they describe themselves is arbitrary. Moreover, you
might override the original YUI component toString() method in your own
instance of a component and render it useless for this purpose.
YUI components register themselves and you can find information about them
at the YAHOO.env.modules array. The keys on that array will be the names of
the modules actually loaded and in each you will find version, built and
A different matter is if you want to know if an object is of a particular
alert(myDataTable instanceof YAHOO.widget.DataTable);
will show true if myDataTable is a an instance of a YUI DataTable. You have
to put the full component name. This is safer if you mean to do a generic
function that can take various types of arguments and do different things
depending on its type. toString() depends on the component developer but
you cannot cheat instanceof (mostly). instaceof will work even of objects
that inherit from other objects, for example, by using YAHOO.lang.extend.
instanceof will correctly report that an instance of SimpleDialog is an
instance of YAHOO.widget.SimpleDialog, of YAHOO.widget.Dialog and of all the
chain up to Module and then Object.
The typeof operator will just say 'object' on any object which is not a big
help. Actually, alert(typeof null) will also report that null is an object.
----- Original Message -----
From: "d_adamkiewicz" <d_adamkiewicz@...>
Sent: Monday, December 03, 2007 11:16 AM
> Hello Folks
> I noticed that, using toString() method
> I can get type name of (any? all?) YUI objects
> but is it better, preferred way?
> yuiObjTypeName = yuiObj.toString().split(" ");
> Yahoo! Groups Links
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.503 / Virus Database: 269.16.13/1165 - Release Date:
> 02/12/2007 20:34