<!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>
</head>
<body>
<script type="text/javascript">
//用函数创建一个person对象
function Person(name,age){
this.name=name;
this.age=age;
this.setName=function setName(name){
this.name=name;
};
this.getName=function getName(){
return this.name;
};
this.setAge=function setAge(age){
this.age=age;
};
this.getAge=function getName(){
return this.name;
};
this.toString=function toString(){
return "[ name: "+this.name+","+" age: "+this.age+"]";
};
};
//使用原型函数
Person.prototype.show=function(){
alert("person run");
};
//创建对象
var p=new Person("wangwu",22);
var p1=new Person("zhangsan",23);
alert(p.name);
alert(p1.toString());
for ( var x in p) {
alert("x="+p[x]);
};
with(p){
name="dalang";
age=21;
};
alert(p.toString());
</script>
</body>
</html>