The acquisition of properties for all JavaScript objects

Source: Internet
Author: User
Tags array error handling eval return sort
javascript| objects

From the first published article, until now to publish a second article, I do not think, I will not send out.

These days have been looking for JavaScript all the objects of the properties and methods, there is no way, had to write a random. First of all, if you have better can be taken out to share, get the object and then check the data, not faster?

<!--
---------------------------------------------------------
Write by Yyuj
To enumerate all member information of an object
---------------------------------------------------------
-->
<form name= "Form1" method= "POST" >
<input type= "text" name= "objname" size= "Document" >
<input type= "Submit" value= "OK" >
</form>
<script language= "JavaScript" >
<!--
function GetInfo ()
{
var Obj=document.form1;
Getobj (Obj.objname.value);
return false;
}
function Getobj (mobjname)
{
Creating variables
var objarray = new Array (); An array to store the name of the variable
var objname=mobjname; Receives the object name (character type) that is passed in from outside
Var TypeName;
--Error handling
Try
{
Enumerate all member information for an object
for (Var i in eval (objname))
{
objarray[objarray.length++] = i;
}
--Get the DIV tag for storing information
var Objinfo=document.getelementbyid ("Objinfo")
Objinfo.innerhtml= ""
Objinfo.innerhtml= "Objname:<b style= ' color= #ff0000 ' >" +objname+ "</b><br>"
--If no member exists, return
if (objarray.length==0)
{
Objinfo.innerhtml= "Objname:<b style= ' color= #ff0000 ' >" +objname+ "</b>--no member exists in existence";
Return
}
--Sort the array
Objarray.sort ();
--Further processing of output information
for (Var k=0;k<objarray.length;k++)
{
Typename=typeof (eval (objname+ ".") +OBJARRAY[K]))
--If the object is directly linked, otherwise do not show
if ("Object" ==typename)
{
objinfo.innerhtml=objinfo.innerhtml+ "|--<a href=\" javascript:getobj (' +objname+ '). +objarray[k]+ "') \" > "+objarray[k]+" </a> ==================== "+typename
}
Else
{
objinfo.innerhtml=objinfo.innerhtml+ "| |" +objarray[k]+ "====================" +typename
}
--underlined, mainly for the sake of beauty
objinfo.innerhtml=objinfo.innerhtml+ "<br>---------------------------------------------------<br>"
}
}
catch (E)
{
Alert ("You are not entering the correct object, please enter the correct object!") If it is, please enter the prefix, \ n \ nplease like, I want to query the body, then I input document.body ");
}
}
-->
</script>
<div name= "Objinfo" id= "Objinfo" ></div>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.