From: JavaEye.com
Prototype provides a JavaScript object-oriented infrastructure, which can be used for object-oriented programming. The method for defining object types is as follows: 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 );
}
}
Use Class. create () to create an object type and define the object type. Note that the initialize method is the Person constructor. The complete HTML is as follows: <Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> Test Object </title>
<Script type = "text/javascript" src = "prototype. js"> </script>
</Head>
<Body>
<Script type = "text/javascript">
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 );
}
}
Var person = new Person ("robbin", 30 );
Person. toString ();
</Script>
</Body>
</Html>