Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    243
    Thanks
    14
    Thanked 2 Times in 2 Posts

    Detecting unknown objects & properties?

    Is there a way to detect unknown object and their properties, without knowing the object/property names beforehand?

    I'm interested in ways to get the code to describe itself, so I can do some research without proper documentation.

    Are there set commands for stuff like this or some clever techniques, is it even possible?

    Thanks!

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Yep, you can do something like this:
    Code:
    function showProps(obj){
     var message="";
     for(prop in obj){
      if(obj.name){ 
       message += obj.name+".";
      }
      message += prop+"="+obj[prop]+"\n";
     }
     alert(message);
    }
    Though you may not like what you find!

  • #3
    Regular Coder
    Join Date
    Jan 2006
    Posts
    243
    Thanks
    14
    Thanked 2 Times in 2 Posts
    Thanks a lot, with a few slight mod's that was exactly what I was looking for!

    Why did you think I might not like it?

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    I seem to remember that looking at certain html objects you end up with tons of properties, most of which are completely irrelevant to what I was after. Perhaps you're after them all, if so great!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •