for in loop to execute properties in an object
with statement: (Object operation statement)
Function: Create default objects for a program
Format:
The code copy is as follows:
with(<object>){
<Sentence Group>
}
Specific examples:
The code copy is as follows:
<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("Rene Liu","female");
//document.write(showProperty(obj,"person"));
with(document){
write(showProperty(obj,"person"));
}
</script>
/*Running effect:
person.name = Rene Liu
person.gender = female
*/
Have you any idea about traversing for in and the usage of with in in in javascript? This is the basis for learning javascript.