码迷,mamicode.com
首页 > 编程语言 > 详细

JAVASCRIPT基础07-for-in循环

时间:2014-07-05 17:38:08      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   os   

<!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=UTF-8">
<title>Insert title here</title>

  <script type="text/javascript"> 
  
    
     //对象字面量
     var man = {
        legs: 2 ,
        hands :2 ,
        head:1 
     }
     
     //给所有的对象生成一个克隆方法
     if(typeof Object.prototype.clone ==="undefined"){
        Object.prototype.clone = function(){
           console.log("clone") ;
        }
     }
     
     
     //for-in循环应用在非数组对象上的遍历上
     
     for(var i in man){
         console.log(i,":",man[i]) ;
      }
     
     //通过hasOwnProperty 过滤原型链上的属性
     for(var i in man) 
       if(man.hasOwnProperty(i))
              console.log(i,":",man[i]) ;
     
     
     
      var s = "1+2 ";
      console.log(s) ;
      console.log(eval(s)) ;


  </script>
  
</head>


<body>


</body>
</html>

 

JAVASCRIPT基础07-for-in循环,布布扣,bubuko.com

JAVASCRIPT基础07-for-in循环

标签:style   blog   http   java   color   os   

原文地址:http://www.cnblogs.com/liaokailin/p/3822928.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!