遍历一个JS对象的属性和方法

示例代码如下:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">  
  5. <title>testExtjs4</title>  
  6.  <script type="text/javascript" src="../js/classextends1.js"></script>   
  7. <script type="text/javascript">  
  8.     for (pro in document){  
  9.         document.write("document."+pro+"="+document[pro]+"<br>");  
  10.     }  
  11. </script>  
  12.   
  13. </head>  
  14. <body>  
  15.   
  16. </body>  
  17. </html>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>testExtjs4</title>
 <script type="text/javascript" src="../js/classextends1.js"></script> 
<script type="text/javascript">
	for (pro in document){
		document.write("document."+pro+"="+document[pro]+"<br>");
	}
</script>

</head>
<body>

</body>
</html>

示例2:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">  
  5. <title>testExtjs4</title>  
  6.   
  7. <script type="text/javascript">  
  8.   
  9.     function Test(){  
  10.         this.prop1='val1';  
  11.         this.prop2='val2';  
  12.         this.prop3='val3';  
  13.         this.tffunction(){  
  14.             return this.prop1;  
  15.         }  
  16.     }  
  17.       
  18.     Test.prototype.tf1 = function(){return this.prop2;};  
  19.       
  20.     var t = new Test();  
  21.     for (pro in t){  
  22.         document.write("t."+pro+"="+t[pro]+"<br>");  
  23.     }  
  24.       
  25.       
  26. </script>  
  27.   
  28. </head>  
  29. <body>  
  30.   
  31. </body>  
  32. </html>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>testExtjs4</title>

<script type="text/javascript">

	function Test(){
		this.prop1='val1';
		this.prop2='val2';
		this.prop3='val3';
		this.tf= function(){
			return this.prop1;
		}
	}
	
	Test.prototype.tf1 = function(){return this.prop2;};
	
	var t = new Test();
	for (pro in t){
		document.write("t."+pro+"="+t[pro]+"<br>");
	}
	
	
</script>

</head>
<body>

</body>
</html>
posted @ 2013-08-14 20:14  mimo0  阅读(193)  评论(0)    收藏  举报