<script type="text/javascript"> function member(name,gender){ this.name=name; this.gender=gender; } function showProperty(obj,objStr){ var str=""; for(var i in obj){ str+=objStr+"."+i+" = "+obj[i]+"<br>" } return str; } var obj =new member("刘若英","女"); //document.write(showProperty(obj,"person")); with(document){ write(showProperty(obj,"person")); } </script> /*运行效果: person.name = 刘若英 person.gender = 女 */
- for in 循环执行一个对象中的属性
- with语句: (对象操作语句)
功能:为一段程序建立默认对象
开始做,坚持做,重复做格式:
with(<对象>){
<语句组>
}