Web Analytics Made Easy -
StatCounter How to get Object Name? - CodingForum

Announcement

Collapse
No announcement yet.

How to get Object Name?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get Object Name?

    Hello List
    again simple question (i think)
    how can i get the object name, say if i have

    function blah()
    {
    ;
    }

    var foo=new blah()
    var foo2=foo;
    //here i like to alert the name of the Object blah() and get its name ( that is "blah")
    alert( foo2...?????) ;

    thanks!

  • #2
    well i found something but..

    its not exactly right but
    foo2.constructor==Blah give gives me true
    and foo2.constructor gives me all the function , but i need only the name...

    Comment


    • #3
      i'm not sure if that's possible.
      bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

      i am a loser geek, crazy with an evil streak,
      yes i do believe there is a violent thing inside of me.

      Comment


      • #4
        <html>
        <head>
        <title>untitled</title>
        <script type="text/javascript" language="JavaScript">

        Object.prototype.get_class = function() {
        var sCon = this.constructor.toString();
        if (sCon)
        return sCon.slice(sCon.indexOf(' ') + 1, sCon.indexOf('('));
        return null;
        }

        function blah() {;}
        var foo = new blah();
        var foo2 = foo;
        alert(foo.get_class());
        alert(foo2.get_class());

        </script>
        </head>
        <body>
        </body>
        </html>

        Comment


        • #5
          adios: good thinking man

          why just not add method to the Object object ...Great!
          but are you sure its the only why ? with adding method?

          Comment


          • #6
            New kind of problem

            ok.. so we know how to get the Object name But what if i have this:

            function blah()
            {
            ;
            }

            var foo=new blah()

            and i like to get the name of the var that hold the Object (in this case 'foo')
            its giving me [Object Object] every time i try to print foo
            even if i make foo.toString() it gives me the constructor function (blah())
            ??
            thanks

            Comment

            Working...
            X