首页 > 代码库 > JAVASCRIPT基础07-for-in循环

JAVASCRIPT基础07-for-in循环

<!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>