<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<body>
<script type= "Text/javascript" >
Create a Person object with a function
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+ "]";
};
};
Using the prototype function
Person.prototype.show=function () {
Alert ("Person run");
};
Creating objects
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>
Javascripte Create object: