Loading ...
Sorry, an error occurred while loading the content.

How to get type name of YUI object?

Expand Messages
  • d_adamkiewicz
    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 =
    Message 1 of 2 , Dec 3, 2007
    • 0 Attachment
      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(" ")[0];

      Regards
      Darek
    • Satyam
      JavaScript does not provide a standard way. All objects inherit from Object and it is customary for them to redefine the toString method to identify
      Message 2 of 2 , Dec 3, 2007
      • 0 Attachment
        JavaScript does not provide a standard way. All objects inherit from Object
        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
        other info.

        A different matter is if you want to know if an object is of a particular
        type, there you are in safer ground. JavaScript provides the 'instanceof'
        operator.

        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.

        Satyam



        ----- Original Message -----
        From: "d_adamkiewicz" <d_adamkiewicz@...>
        To: <ydn-javascript@yahoogroups.com>
        Sent: Monday, December 03, 2007 11:16 AM
        Subject: [ydn-javascript] 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(" ")[0];
        >
        > Regards
        > Darek
        >
        >
        >
        >
        > 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
        >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.