From:JavaEye.com
Prototype provides a JavaScript object-oriented infrastructure that we can use for object-oriented programming, defining object types in the following ways:
var person = class.create ();
Person.prototype = {
Initialize:function (name, age) {
THIS.name = name;
This.age = age;
},
Tostring:function () {
Document.writeln ("[Name]:" +this.name+ "<br>" [age]: "+this.age);
}
}
First use Class.create () to create an object type, and then define the object type, note that the Initialize method is the constructor for person, and the complete HTML is as follows:
<meta http-equiv= "Content-type" content=; text/html Utf-8 "/>
<title>test object</title>
<script type=" Text/javascript "src=" Prototype.js "> </script>
<body>
<script type= "Text/javascript" >
var person = Cl Ass.create ();
Person.prototype = {
initialize:function (name, age) {
this.name = name;
this.age = age;
},
tostring:function () {
document.writeln ("[Name]:" +this.name+ "<br>" + "[age]:" +this.age);
}
}
var person = new Person ("Robbin", 30);
Person.tostring ();
</script>
</body>